libmongocrypt-helper 1.7.4.0.1002 → 1.8.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (396) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
  4. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
  6. data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
  7. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
  14. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
  15. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
  16. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
  19. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
  20. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
  21. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
  22. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
  23. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
  24. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
  25. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
  26. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
  27. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
  28. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
  31. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
  32. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
  33. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
  34. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
  35. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
  36. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
  37. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
  38. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
  39. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
  41. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
  44. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
  45. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
  46. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
  61. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
  62. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
  63. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  64. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  65. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
  66. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  67. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  68. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  69. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  70. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  71. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  72. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  73. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  74. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  75. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  76. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  77. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
  78. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  79. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  80. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  81. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  82. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  83. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  84. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  85. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
  86. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
  87. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  88. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
  89. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
  90. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  91. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  92. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  93. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  94. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
  95. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
  96. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
  97. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  98. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
  99. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
  100. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
  101. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  102. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  103. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  104. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  105. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
  106. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  107. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  108. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  109. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  110. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  111. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  112. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  113. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
  114. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
  115. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
  116. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
  117. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
  118. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
  119. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
  120. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
  121. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
  122. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
  123. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
  124. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
  125. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  126. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  127. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
  128. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
  129. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  130. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  131. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  132. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  133. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  134. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
  135. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
  136. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  137. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  138. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  139. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  140. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  141. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  142. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  143. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
  144. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  145. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  146. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
  147. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  148. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  149. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  150. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
  151. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
  152. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
  153. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  154. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  155. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  156. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  157. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  158. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  159. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
  160. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
  161. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  162. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
  163. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
  164. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  165. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
  166. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
  194. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
  195. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  196. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
  197. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  198. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  199. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  200. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
  202. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  203. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  231. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  243. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  244. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  245. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  246. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  247. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  248. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  249. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  250. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  251. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  252. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  253. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  261. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  262. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  263. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  271. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  272. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  276. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  277. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  281. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  282. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  283. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  284. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  285. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  286. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  288. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  303. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  314. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
  315. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  316. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  317. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  318. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
  319. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  320. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  323. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
  324. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  325. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  326. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  327. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  328. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
  329. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
  330. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
  331. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
  332. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  333. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
  334. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  335. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
  336. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
  337. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  338. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  339. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
  340. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  341. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  342. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
  343. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
  344. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
  345. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
  346. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  347. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  348. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
  349. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
  350. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  351. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
  352. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
  353. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  354. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  355. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  356. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  357. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  358. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  359. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
  360. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  361. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  362. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  363. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
  364. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  365. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
  366. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
  367. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
  368. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
  369. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
  370. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
  371. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
  372. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  373. data/lib/libmongocrypt_helper/version.rb +2 -2
  374. data.tar.gz.sig +0 -0
  375. metadata +154 -26
  376. metadata.gz.sig +0 -0
  377. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  378. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  379. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  380. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  381. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  382. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  383. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  384. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  392. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
  393. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  394. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
  395. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  396. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -6,12 +6,11 @@
6
6
 
7
7
  #include <iostream>
8
8
  #include <random>
9
- #include <thread>
10
9
  #include <string>
10
+ #include <thread>
11
11
  #include <vector>
12
12
 
13
- #if (defined(__GNUC__) && __GNUC__ < 7 && !defined(__clang__)) || \
14
- (defined(_MSC_VER) && _MSC_VER < 1920)
13
+ #if (defined(__GNUC__) && __GNUC__ < 7 && !defined(__clang__)) || (defined(_MSC_VER) && _MSC_VER < 1920)
15
14
  // Old GCC and old MSVC have partially-broken constexpr that prevents us from
16
15
  // properly using static_assert with from_string()
17
16
  #define BROKEN_CONSTEXPR
@@ -19,389 +18,307 @@
19
18
 
20
19
  #ifndef BROKEN_CONSTEXPR
21
20
  // Basic checks with static_asserts, check constexpr correctness and fail fast
22
- static_assert (mlib_int128_eq (MLIB_INT128 (0), MLIB_INT128_FROM_PARTS (0, 0)),
23
- "fail");
24
- static_assert (mlib_int128_eq (MLIB_INT128 (4), MLIB_INT128_FROM_PARTS (4, 0)),
25
- "fail");
26
- static_assert (mlib_int128_eq (MLIB_INT128 (34),
27
- MLIB_INT128_FROM_PARTS (34, 0)),
28
- "fail");
29
- static_assert (mlib_int128_eq (MLIB_INT128 (34 + 8),
30
- MLIB_INT128_FROM_PARTS (42, 0)),
31
- "fail");
32
- static_assert (mlib_int128_eq (MLIB_INT128_CAST (94),
33
- MLIB_INT128_FROM_PARTS (94, 0)),
34
- "fail");
35
- static_assert (mlib_int128_eq (mlib_int128_lshift (MLIB_INT128_CAST (1), 64),
36
- MLIB_INT128_FROM_PARTS (0, 1)),
37
- "fail");
38
- static_assert (mlib_int128_eq (mlib_int128_lshift (MLIB_INT128_CAST (1), 127),
39
- MLIB_INT128_FROM_PARTS (0, 1ull << 63)),
40
- "fail");
41
-
42
- static_assert (mlib_int128_scmp (MLIB_INT128_CAST (2), MLIB_INT128 (0)) > 0,
43
- "fail");
44
- static_assert (mlib_int128_scmp (MLIB_INT128_CAST (-2), MLIB_INT128 (0)) < 0,
45
- "fail");
46
- static_assert (mlib_int128_scmp (MLIB_INT128_CAST (0), MLIB_INT128 (0)) == 0,
47
- "fail");
21
+ static_assert(mlib_int128_eq(MLIB_INT128(0), MLIB_INT128_FROM_PARTS(0, 0)), "fail");
22
+ static_assert(mlib_int128_eq(MLIB_INT128(4), MLIB_INT128_FROM_PARTS(4, 0)), "fail");
23
+ static_assert(mlib_int128_eq(MLIB_INT128(34), MLIB_INT128_FROM_PARTS(34, 0)), "fail");
24
+ static_assert(mlib_int128_eq(MLIB_INT128(34 + 8), MLIB_INT128_FROM_PARTS(42, 0)), "fail");
25
+ static_assert(mlib_int128_eq(MLIB_INT128_CAST(94), MLIB_INT128_FROM_PARTS(94, 0)), "fail");
26
+ static_assert(mlib_int128_eq(mlib_int128_lshift(MLIB_INT128_CAST(1), 64), MLIB_INT128_FROM_PARTS(0, 1)), "fail");
27
+ static_assert(mlib_int128_eq(mlib_int128_lshift(MLIB_INT128_CAST(1), 127), MLIB_INT128_FROM_PARTS(0, 1ull << 63)),
28
+ "fail");
29
+
30
+ static_assert(mlib_int128_scmp(MLIB_INT128_CAST(2), MLIB_INT128(0)) > 0, "fail");
31
+ static_assert(mlib_int128_scmp(MLIB_INT128_CAST(-2), MLIB_INT128(0)) < 0, "fail");
32
+ static_assert(mlib_int128_scmp(MLIB_INT128_CAST(0), MLIB_INT128(0)) == 0, "fail");
48
33
  // Unsigned compare doesn't believe in negative numbers:
49
- static_assert (mlib_int128_ucmp (MLIB_INT128_CAST (-2), MLIB_INT128 (0)) > 0,
50
- "fail");
34
+ static_assert(mlib_int128_ucmp(MLIB_INT128_CAST(-2), MLIB_INT128(0)) > 0, "fail");
51
35
  #endif // BROKEN_CONSTEXPR
52
36
 
53
37
  // Literals, for test convenience:
54
38
  #ifndef BROKEN_CONSTEXPR
55
39
  constexpr
56
40
  #endif
57
- mlib_int128
58
- operator""_i128 (const char *s)
59
- {
60
- return mlib_int128_from_string (s, NULL);
41
+ mlib_int128
42
+ operator""_i128(const char *s) {
43
+ return mlib_int128_from_string(s, NULL);
61
44
  }
62
45
 
63
46
  #ifndef BROKEN_CONSTEXPR
64
47
  constexpr
65
48
  #endif
66
- mlib_int128
67
- operator""_i128 (const char *s, size_t)
68
- {
69
- return mlib_int128_from_string (s, NULL);
49
+ mlib_int128
50
+ operator""_i128(const char *s, size_t) {
51
+ return mlib_int128_from_string(s, NULL);
70
52
  }
71
53
 
72
54
  // Operators, for test convenience
73
- constexpr bool
74
- operator== (mlib_int128 l, mlib_int128 r)
75
- {
76
- return mlib_int128_eq (l, r);
55
+ constexpr bool operator==(mlib_int128 l, mlib_int128 r) {
56
+ return mlib_int128_eq(l, r);
77
57
  }
78
58
 
79
- constexpr bool
80
- operator<(mlib_int128 l, mlib_int128 r)
81
- {
82
- return mlib_int128_scmp (l, r) < 0;
59
+ constexpr bool operator<(mlib_int128 l, mlib_int128 r) {
60
+ return mlib_int128_scmp(l, r) < 0;
83
61
  }
84
62
 
85
63
  #ifndef BROKEN_CONSTEXPR
86
- static_assert (mlib_int128_eq (MLIB_INT128 (0), 0_i128), "fail");
87
- static_assert (mlib_int128_eq (MLIB_INT128 (65025), 65025_i128), "fail");
88
- static_assert (mlib_int128_eq (MLIB_INT128_FROM_PARTS (0, 1),
89
- 18446744073709551616_i128),
90
- "fail");
91
- static_assert (mlib_int128_eq (MLIB_INT128_UMAX,
92
- 340282366920938463463374607431768211455_i128),
93
- "fail");
94
-
95
- static_assert (mlib_int128_scmp (MLIB_INT128_SMIN, MLIB_INT128_SMAX) < 0,
96
- "fail");
97
- static_assert (mlib_int128_scmp (MLIB_INT128_SMAX, MLIB_INT128_SMIN) > 0,
98
- "fail");
99
- static_assert (mlib_int128_scmp (MLIB_INT128_CAST (-12), MLIB_INT128_CAST (0)) <
100
- 0,
101
- "fail");
102
- static_assert (mlib_int128_scmp (MLIB_INT128_CAST (12), MLIB_INT128_CAST (0)) >
103
- 0,
104
- "fail");
64
+ static_assert(mlib_int128_eq(MLIB_INT128(0), 0_i128), "fail");
65
+ static_assert(mlib_int128_eq(MLIB_INT128(65025), 65025_i128), "fail");
66
+ static_assert(mlib_int128_eq(MLIB_INT128_FROM_PARTS(0, 1), 18446744073709551616_i128), "fail");
67
+ static_assert(mlib_int128_eq(MLIB_INT128_UMAX, 340282366920938463463374607431768211455_i128), "fail");
68
+
69
+ static_assert(mlib_int128_scmp(MLIB_INT128_SMIN, MLIB_INT128_SMAX) < 0, "fail");
70
+ static_assert(mlib_int128_scmp(MLIB_INT128_SMAX, MLIB_INT128_SMIN) > 0, "fail");
71
+ static_assert(mlib_int128_scmp(MLIB_INT128_CAST(-12), MLIB_INT128_CAST(0)) < 0, "fail");
72
+ static_assert(mlib_int128_scmp(MLIB_INT128_CAST(12), MLIB_INT128_CAST(0)) > 0, "fail");
105
73
 
106
74
  // Simple arithmetic:
107
- static_assert (mlib_int128_scmp (mlib_int128_add (MLIB_INT128_SMAX, 1_i128),
108
- MLIB_INT128_SMIN) == 0,
109
- "fail");
110
- static_assert (mlib_int128_scmp (mlib_int128_negate (MLIB_INT128_CAST (-42)),
111
- MLIB_INT128 (42)) == 0,
112
- "fail");
113
- static_assert (mlib_int128_scmp (mlib_int128_sub (5_i128, 3_i128), 2_i128) == 0,
114
- "fail");
115
- static_assert (mlib_int128_scmp (mlib_int128_sub (3_i128, 5_i128),
116
- mlib_int128_negate (2_i128)) == 0,
117
- "fail");
118
- static_assert (mlib_int128_ucmp (mlib_int128_sub (3_i128, 5_i128),
119
- mlib_int128_sub (MLIB_INT128_UMAX, 1_i128)) ==
120
- 0,
121
- "fail");
122
-
123
- static_assert (mlib_int128_scmp (mlib_int128_lshift (1_i128, 127),
124
- MLIB_INT128_SMIN) == 0,
125
- "fail");
126
-
127
- static_assert (
128
- mlib_int128_scmp (mlib_int128_rshift (mlib_int128_lshift (1_i128, 127), 127),
129
- 1_i128) == 0,
130
- "fail");
75
+ static_assert(mlib_int128_scmp(mlib_int128_add(MLIB_INT128_SMAX, 1_i128), MLIB_INT128_SMIN) == 0, "fail");
76
+ static_assert(mlib_int128_scmp(mlib_int128_negate(MLIB_INT128_CAST(-42)), MLIB_INT128(42)) == 0, "fail");
77
+ static_assert(mlib_int128_scmp(mlib_int128_sub(5_i128, 3_i128), 2_i128) == 0, "fail");
78
+ static_assert(mlib_int128_scmp(mlib_int128_sub(3_i128, 5_i128), mlib_int128_negate(2_i128)) == 0, "fail");
79
+ static_assert(mlib_int128_ucmp(mlib_int128_sub(3_i128, 5_i128), mlib_int128_sub(MLIB_INT128_UMAX, 1_i128)) == 0,
80
+ "fail");
81
+
82
+ static_assert(mlib_int128_scmp(mlib_int128_lshift(1_i128, 127), MLIB_INT128_SMIN) == 0, "fail");
83
+
84
+ static_assert(mlib_int128_scmp(mlib_int128_rshift(mlib_int128_lshift(1_i128, 127), 127), 1_i128) == 0, "fail");
131
85
 
132
86
  // With no high-32 bits in the denominator
133
- static_assert (mlib_int128_div (316356263640858117670580590964547584140_i128,
134
- 13463362962560749016052695684_i128) ==
135
- 23497566285_i128,
136
- "fail");
87
+ static_assert(mlib_int128_div(316356263640858117670580590964547584140_i128, 13463362962560749016052695684_i128)
88
+ == 23497566285_i128,
89
+ "fail");
137
90
 
138
91
  // Remainder correctness with high bit set:
139
- static_assert (mlib_int128_mod (292590981272581782572061492191999425232_i128,
140
- 221673222198185508195462959065350495048_i128) ==
141
- 70917759074396274376598533126648930184_i128,
142
- "fail");
92
+ static_assert(mlib_int128_mod(292590981272581782572061492191999425232_i128,
93
+ 221673222198185508195462959065350495048_i128)
94
+ == 70917759074396274376598533126648930184_i128,
95
+ "fail");
143
96
 
144
97
  // Remainder with 64bit denom:
145
- static_assert (mlib_int128_mod (2795722437127403543495742528_i128,
146
- 708945413_i128) == 619266642_i128,
147
- "fail");
98
+ static_assert(mlib_int128_mod(2795722437127403543495742528_i128, 708945413_i128) == 619266642_i128, "fail");
148
99
 
149
100
  // 10-div:
150
- static_assert (mlib_int128_div (MLIB_INT128_SMAX, 10_i128) ==
151
- 17014118346046923173168730371588410572_i128,
152
- "fail");
101
+ static_assert(mlib_int128_div(MLIB_INT128_SMAX, 10_i128) == 17014118346046923173168730371588410572_i128, "fail");
153
102
  #endif // BROKEN_CONSTEXPR
154
103
 
155
- inline std::ostream &
156
- operator<< (std::ostream &out, const mlib_int128 &v)
157
- {
158
- out << mlib_int128_format (v).str;
159
- return out;
104
+ inline std::ostream &operator<<(std::ostream &out, const mlib_int128 &v) {
105
+ out << mlib_int128_format(v).str;
106
+ return out;
160
107
  }
161
108
 
162
109
  #ifndef BROKEN_CONSTEXPR
163
- static_assert (mlib_int128 (MLIB_INT128_UMAX) ==
164
- 340282366920938463463374607431768211455_i128,
165
- "fail");
110
+ static_assert(mlib_int128(MLIB_INT128_UMAX) == 340282366920938463463374607431768211455_i128, "fail");
166
111
 
167
112
  // Check sign extension works correctly:
168
- static_assert (mlib_int128 (MLIB_INT128_CAST (INT64_MIN)) ==
169
- mlib_int128_negate (9223372036854775808_i128),
170
- "fail");
171
- static_assert (mlib_int128 (MLIB_INT128_CAST (INT64_MIN)) <
172
- mlib_int128_negate (9223372036854775807_i128),
173
- "fail");
174
- static_assert (mlib_int128_negate (9223372036854775809_i128) <
175
- mlib_int128 (MLIB_INT128_CAST (INT64_MIN)),
176
- "fail");
113
+ static_assert(mlib_int128(MLIB_INT128_CAST(INT64_MIN)) == mlib_int128_negate(9223372036854775808_i128), "fail");
114
+ static_assert(mlib_int128(MLIB_INT128_CAST(INT64_MIN)) < mlib_int128_negate(9223372036854775807_i128), "fail");
115
+ static_assert(mlib_int128_negate(9223372036854775809_i128) < mlib_int128(MLIB_INT128_CAST(INT64_MIN)), "fail");
177
116
  #endif
178
117
 
179
118
  #ifdef __SIZEOF_INT128__
180
119
  // mlib_int128_to_native converts mlib_int128 to native __uint128_t.
181
120
  // Endian-ness is accounted for.
182
- static __uint128_t
183
- mlib_int128_to_native (mlib_int128 in)
184
- {
185
- __uint128_t out;
186
- uint8_t *out_u8 = (uint8_t *) &out;
187
- if (MLIB_IS_BIG_ENDIAN) {
188
- // Copy hi, then lo.
189
- memcpy (out_u8, &in.r.hi, sizeof (in.r.hi));
190
- memcpy (out_u8 + sizeof (in.r.hi), &in.r.lo, sizeof (in.r.lo));
191
- } else {
192
- // Copy lo, then hi.
193
- memcpy (out_u8, &in.r.lo, sizeof (in.r.lo));
194
- memcpy (out_u8 + sizeof (in.r.lo), &in.r.hi, sizeof (in.r.hi));
195
- }
196
- return out;
121
+ static __uint128_t mlib_int128_to_native(mlib_int128 in) {
122
+ __uint128_t out;
123
+ uint8_t *out_u8 = (uint8_t *)&out;
124
+ if (MLIB_IS_BIG_ENDIAN) {
125
+ // Copy hi, then lo.
126
+ memcpy(out_u8, &in.r.hi, sizeof(in.r.hi));
127
+ memcpy(out_u8 + sizeof(in.r.hi), &in.r.lo, sizeof(in.r.lo));
128
+ } else {
129
+ // Copy lo, then hi.
130
+ memcpy(out_u8, &in.r.lo, sizeof(in.r.lo));
131
+ memcpy(out_u8 + sizeof(in.r.lo), &in.r.hi, sizeof(in.r.hi));
132
+ }
133
+ return out;
197
134
  }
198
135
 
199
136
  // native_to_mlib_int128 converts native __uint128_t to mlib_int128.
200
137
  // Endian-ness is accounted for.
201
- static mlib_int128
202
- native_to_mlib_int128 (__uint128_t in)
203
- {
204
- mlib_int128 out;
205
- uint8_t *in_u8 = (uint8_t *) &in;
206
- if (MLIB_IS_BIG_ENDIAN) {
207
- // Copy hi, then lo.
208
- memcpy (&out.r.hi, in_u8, sizeof (out.r.hi));
209
- memcpy (&out.r.lo, in_u8 + sizeof (out.r.hi), sizeof (out.r.lo));
210
- } else {
211
- // Copy lo, then hi.
212
- memcpy (&out.r.lo, in_u8, sizeof (out.r.lo));
213
- memcpy (&out.r.hi, in_u8 + sizeof (out.r.lo), sizeof (out.r.hi));
214
- }
215
- return out;
138
+ static mlib_int128 native_to_mlib_int128(__uint128_t in) {
139
+ mlib_int128 out;
140
+ uint8_t *in_u8 = (uint8_t *)&in;
141
+ if (MLIB_IS_BIG_ENDIAN) {
142
+ // Copy hi, then lo.
143
+ memcpy(&out.r.hi, in_u8, sizeof(out.r.hi));
144
+ memcpy(&out.r.lo, in_u8 + sizeof(out.r.hi), sizeof(out.r.lo));
145
+ } else {
146
+ // Copy lo, then hi.
147
+ memcpy(&out.r.lo, in_u8, sizeof(out.r.lo));
148
+ memcpy(&out.r.hi, in_u8 + sizeof(out.r.lo), sizeof(out.r.hi));
149
+ }
150
+ return out;
216
151
  }
217
152
  #endif // __SIZEOF_INT128__
218
153
 
219
- static mlib_int128_divmod_result
220
- div_check (mlib_int128 num, mlib_int128 den)
221
- {
222
- // std::cout << "Check: " << num << " ÷ " << den << '\n';
223
- mlib_int128_divmod_result res = mlib_int128_divmod (num, den);
154
+ static mlib_int128_divmod_result div_check(mlib_int128 num, mlib_int128 den) {
155
+ // std::cout << "Check: " << num << " ÷ " << den << '\n';
156
+ mlib_int128_divmod_result res = mlib_int128_divmod(num, den);
224
157
  #ifdef __SIZEOF_INT128__
225
- // When we have an existing i128 impl, test against that:
226
- __uint128_t num1 = mlib_int128_to_native (num);
227
- __uint128_t den1 = mlib_int128_to_native (den);
228
- __uint128_t q = num1 / den1;
229
- __uint128_t r = num1 % den1;
230
- mlib_int128_divmod_result expect;
231
- expect.quotient = native_to_mlib_int128 (q);
232
- expect.remainder = native_to_mlib_int128 (r);
233
- if (!mlib_int128_eq (expect.quotient, res.quotient) ||
234
- !mlib_int128_eq (expect.remainder, res.remainder)) {
235
- std::cout << "unexpected result in division"
236
- << " num=" << mlib_int128_format (num).str
237
- << " den=" << mlib_int128_format (den).str
238
- << " expect.quotient="
239
- << mlib_int128_format (expect.quotient).str
240
- << " expect.remainder="
241
- << mlib_int128_format (expect.remainder).str << std::endl;
242
- }
243
- CHECK (expect.quotient == res.quotient);
244
- CHECK (expect.remainder == res.remainder);
158
+ // When we have an existing i128 impl, test against that:
159
+ __uint128_t num1 = mlib_int128_to_native(num);
160
+ __uint128_t den1 = mlib_int128_to_native(den);
161
+ __uint128_t q = num1 / den1;
162
+ __uint128_t r = num1 % den1;
163
+ mlib_int128_divmod_result expect;
164
+ expect.quotient = native_to_mlib_int128(q);
165
+ expect.remainder = native_to_mlib_int128(r);
166
+ if (!mlib_int128_eq(expect.quotient, res.quotient) || !mlib_int128_eq(expect.remainder, res.remainder)) {
167
+ std::cout << "unexpected result in division"
168
+ << " num=" << mlib_int128_format(num).str << " den=" << mlib_int128_format(den).str
169
+ << " expect.quotient=" << mlib_int128_format(expect.quotient).str
170
+ << " expect.remainder=" << mlib_int128_format(expect.remainder).str << std::endl;
171
+ }
172
+ CHECK(expect.quotient == res.quotient);
173
+ CHECK(expect.remainder == res.remainder);
245
174
  #endif
246
- // Check inversion by multiplication provides the correct result
247
- auto invert = mlib_int128_mul (res.quotient, den);
248
- invert = mlib_int128_add (invert, res.remainder);
249
- CHECK (invert == num);
250
- return res;
175
+ // Check inversion by multiplication provides the correct result
176
+ auto invert = mlib_int128_mul(res.quotient, den);
177
+ invert = mlib_int128_add(invert, res.remainder);
178
+ CHECK(invert == num);
179
+ return res;
251
180
  }
252
181
 
253
182
  // Runtime checks, easier to debug that static_asserts
254
- int
255
- main ()
256
- {
257
- mlib_int128 zero = MLIB_INT128 (0);
258
- CHECK (mlib_int128_eq (zero, MLIB_INT128 (0)));
259
- CHECK (mlib_int128_eq (zero, 0_i128));
260
- CHECK (zero == 0_i128);
261
-
262
- auto two = MLIB_INT128 (2);
263
- auto four = mlib_int128_add (two, two);
264
- CHECK (four == MLIB_INT128 (4));
265
- CHECK (four == 4_i128);
266
- CHECK (two == mlib_int128_add (two, zero));
267
-
268
- // Addition wraps:
269
- mlib_int128 max = MLIB_INT128_SMAX;
270
- auto more = mlib_int128_add (max, four);
271
- CHECK (more == mlib_int128_add (MLIB_INT128_SMIN, MLIB_INT128 (3)));
272
-
273
- // "Wrap" around zero:
274
- auto ntwo = MLIB_INT128_CAST (-2);
275
- auto sum = mlib_int128_add (ntwo, four);
276
- CHECK (sum == two);
277
-
278
- auto eight = mlib_int128_lshift (two, 2);
279
- CHECK (eight == MLIB_INT128 (8));
280
-
281
- auto big = mlib_int128_lshift (two, 72);
282
- CHECK (mlib_int128_scmp (big, MLIB_INT128 (0)) > 0);
283
-
284
- auto four_v2 = mlib_int128_lshift (eight, -1);
285
- CHECK (four == four_v2);
286
-
287
- // Negative literals:
288
- CHECK (MLIB_INT128 (-64) == mlib_int128_negate (64_i128));
289
-
290
- CHECK (mlib_int128_mul (1_i128, 2_i128) == 2_i128);
291
- CHECK (mlib_int128_mul (1_i128, 0_i128) == 0_i128);
292
- CHECK (mlib_int128_mul (0_i128, 0_i128) == 0_i128);
293
- CHECK (mlib_int128_mul (2_i128, 73_i128) == 146_i128);
294
- CHECK (mlib_int128_mul (28468554863115876158655557_i128, 73_i128) ==
295
- 2078204505007458959581855661_i128);
296
- CHECK (mlib_int128_mul (MLIB_INT128_CAST (-7), 4_i128) ==
297
- MLIB_INT128_CAST (-28));
298
- CHECK (mlib_int128_mul (MLIB_INT128_CAST (-7), MLIB_INT128_CAST (-7)) ==
299
- 49_i128);
300
-
301
- // It's useful to specify bit patterns directly
302
- auto in_binary =
303
- 0b110101010110100100001101111001111010100010111100100101101011010110101001010110110011000100000100011110010101101001111110001000_i128;
304
- CHECK (in_binary == 70917759074396274376598533126648930184_i128);
305
- CHECK (
306
- in_binary ==
307
- "0b110101010110100100001101111001111010100010111100100101101011010110101001010110110011000100000100011110010101101001111110001000"_i128);
308
-
309
- // Or hexadecimal
310
- auto in_hex = 0x355a4379ea2f25ad6a56cc411e569f88_i128;
311
- CHECK (in_hex == 70917759074396274376598533126648930184_i128);
312
-
313
- int8_t n = -12;
314
- CHECK (mlib_int128_scmp (zero, MLIB_INT128_CAST (n)) > 0);
315
- CHECK (mlib_int128_ucmp (zero, MLIB_INT128_CAST (n)) < 0);
316
-
317
- auto _2pow127 = mlib_int128_pow2 (127);
318
- CHECK (std::string (mlib_int128_format (_2pow127).str) ==
319
- "170141183460469231731687303715884105728");
320
-
321
- auto r = div_check (27828649044156246570177174673037165454_i128,
322
- 499242349997913298655486252455941907_i128);
323
-
324
- CHECK (r.quotient == 55_i128);
325
- CHECK (r.remainder == 370319794271015144125430787960360569_i128);
326
-
327
- r = div_check (64208687961221311123721027584_i128, 3322092839076102144_i128);
328
- CHECK (r.remainder == 3155565729965670400_i128);
329
-
330
- // This division will trigger the rare Knuth 4.3.1D/D6 condition:
331
- r = div_check (31322872034807296605612234499929458960_i128,
332
- 34573864092216774938021667884_i128);
333
- CHECK (r.quotient == 905969663_i128);
334
- CHECK (r.remainder == 34573864092065898160364055868_i128);
335
-
336
- // Self-divide:
337
- r = div_check (628698094597401606590302208_i128,
338
- 628698094597401606590302208_i128);
339
- CHECK (r.quotient == 1_i128);
340
- CHECK (r.remainder == 0_i128);
341
-
342
- // With no high-32 bits in the denominator
343
- r = div_check (316356263640858117670580590964547584140_i128,
344
- 13463362962560749016052695684_i128);
345
- CHECK (r.quotient == 23497566285_i128);
346
-
347
- // Remainder correctness with high bit set:
348
- r = div_check (292590981272581782572061492191999425232_i128,
349
- 221673222198185508195462959065350495048_i128);
350
- CHECK (r.remainder == 70917759074396274376598533126648930184_i128);
351
-
352
- // Remainder with 64bit denom:
353
- r = div_check (2795722437127403543495742528_i128, 708945413_i128);
354
- CHECK (r.remainder == 619266642_i128);
355
-
356
- // 10-div:
357
- CHECK (mlib_int128_div (MLIB_INT128_SMAX, 10_i128) ==
358
- 17014118346046923173168730371588410572_i128);
359
-
360
- std::random_device rd;
361
- std::seed_seq seed ({rd (), rd (), rd (), rd ()});
362
- // Pick every numerator bit pattern from 0b00'00 to 0b11'11
363
- for (auto nbits = 0u; nbits < 16u; ++nbits) {
364
- // This is an extremely rudimentary thread pool to parallelize the
365
- // division checks. It doesn't need to be rigorous or optimal, it only
366
- // needs to "just work."
367
- std::vector<std::thread> threads;
368
- // Pick every denominator bit pattern from 0b00'01 to 0b11'11:
369
- for (auto dbits = 1u; dbits < 16u; ++dbits) {
370
- // Randomness:
371
- std::mt19937 random;
372
- random.seed (seed);
373
- // Spawn a thread for this denominator bit pattern:
374
- threads.emplace_back ([nbits, dbits, random] () mutable {
375
- std::uniform_int_distribution<std::uint32_t> dist;
376
- // 100k random divisions:
377
- for (auto i = 0; i < 100000; ++i) {
378
- // Generate a denominator
379
- auto den = 0_i128;
380
- while (den == 0_i128) {
381
- // Regenerate until we don't have zero (very
382
- // unlikely, but be safe!)
383
- uint64_t dlo = 0, dhi = 0;
384
- (dbits & 1) && (dlo |= dist (random));
385
- (dbits & 2) && (dlo |= (uint64_t) dist (random) << 32);
386
- (dbits & 4) && (dhi |= dist (random));
387
- (dbits & 8) && (dhi |= (uint64_t) dist (random) << 32);
388
- den = MLIB_INT128_FROM_PARTS (dlo, dhi);
389
- }
390
- // Generate a numerator
391
- uint64_t nlo = 0, nhi = 0;
392
- (nbits & 1) && (nlo |= dist (random));
393
- (nbits & 2) && (nlo |= (uint64_t) dist (random) << 32);
394
- (nbits & 4) && (nhi |= dist (random));
395
- (nbits & 8) && (nhi |= (uint64_t) dist (random) << 32);
396
- mlib_int128 num = MLIB_INT128_FROM_PARTS (nlo, nhi);
397
- // Divide them:
398
- div_check (num, den);
399
- }
400
- });
401
- }
402
- // Join the threads that are dividing:
403
- for (auto &t : threads) {
404
- t.join ();
405
- }
406
- }
183
+ int main() {
184
+ mlib_int128 zero = MLIB_INT128(0);
185
+ CHECK(mlib_int128_eq(zero, MLIB_INT128(0)));
186
+ CHECK(mlib_int128_eq(zero, 0_i128));
187
+ CHECK(zero == 0_i128);
188
+
189
+ auto two = MLIB_INT128(2);
190
+ auto four = mlib_int128_add(two, two);
191
+ CHECK(four == MLIB_INT128(4));
192
+ CHECK(four == 4_i128);
193
+ CHECK(two == mlib_int128_add(two, zero));
194
+
195
+ // Addition wraps:
196
+ mlib_int128 max = MLIB_INT128_SMAX;
197
+ auto more = mlib_int128_add(max, four);
198
+ CHECK(more == mlib_int128_add(MLIB_INT128_SMIN, MLIB_INT128(3)));
199
+
200
+ // "Wrap" around zero:
201
+ auto ntwo = MLIB_INT128_CAST(-2);
202
+ auto sum = mlib_int128_add(ntwo, four);
203
+ CHECK(sum == two);
204
+
205
+ auto eight = mlib_int128_lshift(two, 2);
206
+ CHECK(eight == MLIB_INT128(8));
207
+
208
+ auto big = mlib_int128_lshift(two, 72);
209
+ CHECK(mlib_int128_scmp(big, MLIB_INT128(0)) > 0);
210
+
211
+ auto four_v2 = mlib_int128_lshift(eight, -1);
212
+ CHECK(four == four_v2);
213
+
214
+ // Negative literals:
215
+ CHECK(MLIB_INT128(-64) == mlib_int128_negate(64_i128));
216
+
217
+ CHECK(mlib_int128_mul(1_i128, 2_i128) == 2_i128);
218
+ CHECK(mlib_int128_mul(1_i128, 0_i128) == 0_i128);
219
+ CHECK(mlib_int128_mul(0_i128, 0_i128) == 0_i128);
220
+ CHECK(mlib_int128_mul(2_i128, 73_i128) == 146_i128);
221
+ CHECK(mlib_int128_mul(28468554863115876158655557_i128, 73_i128) == 2078204505007458959581855661_i128);
222
+ CHECK(mlib_int128_mul(MLIB_INT128_CAST(-7), 4_i128) == MLIB_INT128_CAST(-28));
223
+ CHECK(mlib_int128_mul(MLIB_INT128_CAST(-7), MLIB_INT128_CAST(-7)) == 49_i128);
224
+
225
+ // It's useful to specify bit patterns directly
226
+ auto in_binary =
227
+ 0b110101010110100100001101111001111010100010111100100101101011010110101001010110110011000100000100011110010101101001111110001000_i128;
228
+ CHECK(in_binary == 70917759074396274376598533126648930184_i128);
229
+ CHECK(
230
+ in_binary
231
+ == "0b110101010110100100001101111001111010100010111100100101101011010110101001010110110011000100000100011110010101101001111110001000"_i128);
232
+
233
+ // Or hexadecimal
234
+ auto in_hex = 0x355a4379ea2f25ad6a56cc411e569f88_i128;
235
+ CHECK(in_hex == 70917759074396274376598533126648930184_i128);
236
+
237
+ int8_t n = -12;
238
+ CHECK(mlib_int128_scmp(zero, MLIB_INT128_CAST(n)) > 0);
239
+ CHECK(mlib_int128_ucmp(zero, MLIB_INT128_CAST(n)) < 0);
240
+
241
+ auto _2pow127 = mlib_int128_pow2(127);
242
+ CHECK(std::string(mlib_int128_format(_2pow127).str) == "170141183460469231731687303715884105728");
243
+
244
+ auto r = div_check(27828649044156246570177174673037165454_i128, 499242349997913298655486252455941907_i128);
245
+
246
+ CHECK(r.quotient == 55_i128);
247
+ CHECK(r.remainder == 370319794271015144125430787960360569_i128);
248
+
249
+ r = div_check(64208687961221311123721027584_i128, 3322092839076102144_i128);
250
+ CHECK(r.remainder == 3155565729965670400_i128);
251
+
252
+ // This division will trigger the rare Knuth 4.3.1D/D6 condition:
253
+ r = div_check(31322872034807296605612234499929458960_i128, 34573864092216774938021667884_i128);
254
+ CHECK(r.quotient == 905969663_i128);
255
+ CHECK(r.remainder == 34573864092065898160364055868_i128);
256
+
257
+ // Self-divide:
258
+ r = div_check(628698094597401606590302208_i128, 628698094597401606590302208_i128);
259
+ CHECK(r.quotient == 1_i128);
260
+ CHECK(r.remainder == 0_i128);
261
+
262
+ // With no high-32 bits in the denominator
263
+ r = div_check(316356263640858117670580590964547584140_i128, 13463362962560749016052695684_i128);
264
+ CHECK(r.quotient == 23497566285_i128);
265
+
266
+ // Remainder correctness with high bit set:
267
+ r = div_check(292590981272581782572061492191999425232_i128, 221673222198185508195462959065350495048_i128);
268
+ CHECK(r.remainder == 70917759074396274376598533126648930184_i128);
269
+
270
+ // Remainder with 64bit denom:
271
+ r = div_check(2795722437127403543495742528_i128, 708945413_i128);
272
+ CHECK(r.remainder == 619266642_i128);
273
+
274
+ // 10-div:
275
+ CHECK(mlib_int128_div(MLIB_INT128_SMAX, 10_i128) == 17014118346046923173168730371588410572_i128);
276
+
277
+ std::random_device rd;
278
+ std::seed_seq seed({rd(), rd(), rd(), rd()});
279
+ // Pick every numerator bit pattern from 0b00'00 to 0b11'11
280
+ for (auto nbits = 0u; nbits < 16u; ++nbits) {
281
+ // This is an extremely rudimentary thread pool to parallelize the
282
+ // division checks. It doesn't need to be rigorous or optimal, it only
283
+ // needs to "just work."
284
+ std::vector<std::thread> threads;
285
+ // Pick every denominator bit pattern from 0b00'01 to 0b11'11:
286
+ for (auto dbits = 1u; dbits < 16u; ++dbits) {
287
+ // Randomness:
288
+ std::mt19937 random;
289
+ random.seed(seed);
290
+ // Spawn a thread for this denominator bit pattern:
291
+ threads.emplace_back([nbits, dbits, random]() mutable {
292
+ std::uniform_int_distribution<std::uint32_t> dist;
293
+ // 100k random divisions:
294
+ for (auto i = 0; i < 100000; ++i) {
295
+ // Generate a denominator
296
+ auto den = 0_i128;
297
+ while (den == 0_i128) {
298
+ // Regenerate until we don't have zero (very
299
+ // unlikely, but be safe!)
300
+ uint64_t dlo = 0, dhi = 0;
301
+ (dbits & 1) && (dlo |= dist(random));
302
+ (dbits & 2) && (dlo |= (uint64_t)dist(random) << 32);
303
+ (dbits & 4) && (dhi |= dist(random));
304
+ (dbits & 8) && (dhi |= (uint64_t)dist(random) << 32);
305
+ den = MLIB_INT128_FROM_PARTS(dlo, dhi);
306
+ }
307
+ // Generate a numerator
308
+ uint64_t nlo = 0, nhi = 0;
309
+ (nbits & 1) && (nlo |= dist(random));
310
+ (nbits & 2) && (nlo |= (uint64_t)dist(random) << 32);
311
+ (nbits & 4) && (nhi |= dist(random));
312
+ (nbits & 8) && (nhi |= (uint64_t)dist(random) << 32);
313
+ mlib_int128 num = MLIB_INT128_FROM_PARTS(nlo, nhi);
314
+ // Divide them:
315
+ div_check(num, den);
316
+ }
317
+ });
318
+ }
319
+ // Join the threads that are dividing:
320
+ for (auto &t : threads) {
321
+ t.join();
322
+ }
323
+ }
407
324
  }