@grain/stdlib 0.5.13 → 0.6.1

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 (155) hide show
  1. package/CHANGELOG.md +201 -0
  2. package/LICENSE +1 -1
  3. package/README.md +25 -2
  4. package/array.gr +1512 -199
  5. package/array.md +2032 -94
  6. package/bigint.gr +239 -140
  7. package/bigint.md +450 -106
  8. package/buffer.gr +595 -102
  9. package/buffer.md +903 -145
  10. package/bytes.gr +401 -110
  11. package/bytes.md +551 -63
  12. package/char.gr +228 -49
  13. package/char.md +373 -7
  14. package/exception.gr +26 -12
  15. package/exception.md +29 -5
  16. package/float32.gr +130 -109
  17. package/float32.md +185 -57
  18. package/float64.gr +112 -99
  19. package/float64.md +185 -57
  20. package/hash.gr +62 -40
  21. package/hash.md +27 -3
  22. package/int16.gr +430 -0
  23. package/int16.md +618 -0
  24. package/int32.gr +200 -269
  25. package/int32.md +254 -289
  26. package/int64.gr +142 -225
  27. package/int64.md +254 -289
  28. package/int8.gr +511 -0
  29. package/int8.md +786 -0
  30. package/json.gr +2071 -0
  31. package/json.md +646 -0
  32. package/list.gr +120 -68
  33. package/list.md +125 -80
  34. package/map.gr +560 -57
  35. package/map.md +672 -56
  36. package/marshal.gr +239 -227
  37. package/marshal.md +36 -4
  38. package/number.gr +626 -676
  39. package/number.md +738 -153
  40. package/option.gr +33 -35
  41. package/option.md +58 -42
  42. package/package.json +2 -2
  43. package/path.gr +148 -187
  44. package/path.md +47 -96
  45. package/pervasives.gr +75 -416
  46. package/pervasives.md +85 -180
  47. package/priorityqueue.gr +433 -74
  48. package/priorityqueue.md +422 -54
  49. package/queue.gr +362 -80
  50. package/queue.md +433 -38
  51. package/random.gr +67 -75
  52. package/random.md +68 -40
  53. package/range.gr +135 -63
  54. package/range.md +198 -43
  55. package/rational.gr +284 -0
  56. package/rational.md +545 -0
  57. package/regex.gr +933 -1066
  58. package/regex.md +59 -60
  59. package/result.gr +23 -25
  60. package/result.md +54 -39
  61. package/runtime/atof/common.gr +78 -82
  62. package/runtime/atof/common.md +22 -10
  63. package/runtime/atof/decimal.gr +102 -127
  64. package/runtime/atof/decimal.md +28 -7
  65. package/runtime/atof/lemire.gr +56 -71
  66. package/runtime/atof/lemire.md +9 -1
  67. package/runtime/atof/parse.gr +83 -110
  68. package/runtime/atof/parse.md +12 -2
  69. package/runtime/atof/slow.gr +28 -35
  70. package/runtime/atof/slow.md +9 -1
  71. package/runtime/atof/table.gr +19 -18
  72. package/runtime/atof/table.md +10 -2
  73. package/runtime/atoi/parse.gr +153 -136
  74. package/runtime/atoi/parse.md +50 -1
  75. package/runtime/bigint.gr +410 -517
  76. package/runtime/bigint.md +71 -57
  77. package/runtime/compare.gr +176 -85
  78. package/runtime/compare.md +31 -1
  79. package/runtime/dataStructures.gr +144 -32
  80. package/runtime/dataStructures.md +267 -31
  81. package/runtime/debugPrint.gr +34 -15
  82. package/runtime/debugPrint.md +37 -5
  83. package/runtime/equal.gr +53 -52
  84. package/runtime/equal.md +30 -1
  85. package/runtime/exception.gr +38 -47
  86. package/runtime/exception.md +10 -8
  87. package/runtime/gc.gr +23 -152
  88. package/runtime/gc.md +13 -17
  89. package/runtime/malloc.gr +31 -31
  90. package/runtime/malloc.md +11 -3
  91. package/runtime/numberUtils.gr +193 -174
  92. package/runtime/numberUtils.md +29 -9
  93. package/runtime/numbers.gr +1695 -1021
  94. package/runtime/numbers.md +1098 -134
  95. package/runtime/string.gr +543 -245
  96. package/runtime/string.md +76 -6
  97. package/runtime/unsafe/constants.gr +30 -13
  98. package/runtime/unsafe/constants.md +80 -0
  99. package/runtime/unsafe/conv.gr +55 -28
  100. package/runtime/unsafe/conv.md +41 -9
  101. package/runtime/unsafe/memory.gr +10 -30
  102. package/runtime/unsafe/memory.md +15 -19
  103. package/runtime/unsafe/tags.gr +37 -21
  104. package/runtime/unsafe/tags.md +88 -8
  105. package/runtime/unsafe/wasmf32.gr +30 -36
  106. package/runtime/unsafe/wasmf32.md +64 -56
  107. package/runtime/unsafe/wasmf64.gr +30 -36
  108. package/runtime/unsafe/wasmf64.md +64 -56
  109. package/runtime/unsafe/wasmi32.gr +49 -66
  110. package/runtime/unsafe/wasmi32.md +102 -94
  111. package/runtime/unsafe/wasmi64.gr +52 -79
  112. package/runtime/unsafe/wasmi64.md +108 -100
  113. package/runtime/utils/printing.gr +13 -15
  114. package/runtime/utils/printing.md +11 -3
  115. package/runtime/wasi.gr +294 -295
  116. package/runtime/wasi.md +62 -42
  117. package/set.gr +574 -64
  118. package/set.md +634 -54
  119. package/stack.gr +181 -64
  120. package/stack.md +271 -42
  121. package/string.gr +453 -533
  122. package/string.md +241 -151
  123. package/uint16.gr +369 -0
  124. package/uint16.md +585 -0
  125. package/uint32.gr +470 -0
  126. package/uint32.md +737 -0
  127. package/uint64.gr +471 -0
  128. package/uint64.md +737 -0
  129. package/uint8.gr +369 -0
  130. package/uint8.md +585 -0
  131. package/uri.gr +1093 -0
  132. package/uri.md +477 -0
  133. package/{sys → wasi}/file.gr +914 -500
  134. package/{sys → wasi}/file.md +454 -50
  135. package/wasi/process.gr +292 -0
  136. package/{sys → wasi}/process.md +164 -6
  137. package/wasi/random.gr +77 -0
  138. package/wasi/random.md +80 -0
  139. package/{sys → wasi}/time.gr +15 -22
  140. package/{sys → wasi}/time.md +5 -5
  141. package/immutablearray.gr +0 -929
  142. package/immutablearray.md +0 -1038
  143. package/immutablemap.gr +0 -493
  144. package/immutablemap.md +0 -479
  145. package/immutablepriorityqueue.gr +0 -360
  146. package/immutablepriorityqueue.md +0 -291
  147. package/immutableset.gr +0 -498
  148. package/immutableset.md +0 -449
  149. package/runtime/debug.gr +0 -2
  150. package/runtime/debug.md +0 -6
  151. package/runtime/unsafe/errors.gr +0 -36
  152. package/runtime/unsafe/errors.md +0 -204
  153. package/sys/process.gr +0 -254
  154. package/sys/random.gr +0 -79
  155. package/sys/random.md +0 -66
package/uint32.gr ADDED
@@ -0,0 +1,470 @@
1
+ /**
2
+ * Utilities for working with the Uint32 type.
3
+ * @example from "uint32" include Uint32
4
+ *
5
+ * @since v0.6.0
6
+ */
7
+ module Uint32
8
+
9
+ from "runtime/unsafe/wasmi32" include WasmI32
10
+ use WasmI32.{ (+), (-), (*), (&), (|), (^), (<<), (>>>), (==), (!=) }
11
+ from "runtime/unsafe/wasmi64" include WasmI64
12
+ from "runtime/unsafe/memory" include Memory
13
+ from "runtime/exception" include Exception
14
+ from "runtime/numbers" include Numbers
15
+ use Numbers.{ reducedUnsignedInteger, coerceNumberToUnsignedWasmI32 }
16
+ from "runtime/dataStructures" include DataStructures
17
+ use DataStructures.{ newUint32 }
18
+
19
+ @unsafe
20
+ let _VALUE_OFFSET = 4n
21
+
22
+ /**
23
+ * Converts a Number to a Uint32.
24
+ *
25
+ * @param number: The value to convert
26
+ * @returns The Number represented as a Uint32
27
+ *
28
+ * @since v0.6.0
29
+ */
30
+ @unsafe
31
+ provide let fromNumber = (number: Number) => {
32
+ let result = newUint32(coerceNumberToUnsignedWasmI32(number))
33
+ WasmI32.toGrain(result): Uint32
34
+ }
35
+
36
+ /**
37
+ * Converts a Uint32 to a Number.
38
+ *
39
+ * @param value: The value to convert
40
+ * @returns The Uint32 represented as a Number
41
+ *
42
+ * @since v0.6.0
43
+ */
44
+ @unsafe
45
+ provide let toNumber = (value: Uint32) => {
46
+ WasmI32.toGrain(
47
+ reducedUnsignedInteger(
48
+ WasmI64.extendI32U(WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET))
49
+ )
50
+ ): Number
51
+ }
52
+
53
+ /**
54
+ * Converts an Int32 to a Uint32.
55
+ *
56
+ * @param number: The value to convert
57
+ * @returns The Int32 represented as a Uint32
58
+ *
59
+ * @since v0.6.0
60
+ */
61
+ @unsafe
62
+ provide let fromInt32 = (number: Int32) => {
63
+ let x = WasmI32.load(WasmI32.fromGrain(number), _VALUE_OFFSET)
64
+ let result = newUint32(x)
65
+ WasmI32.toGrain(result): Uint32
66
+ }
67
+
68
+ /**
69
+ * Increments the value by one.
70
+ *
71
+ * @param value: The value to increment
72
+ * @returns The incremented value
73
+ *
74
+ * @since v0.6.0
75
+ */
76
+ @unsafe
77
+ provide let incr = (value: Uint32) => {
78
+ let value = WasmI32.fromGrain(value)
79
+ let ptr = newUint32(WasmI32.load(value, _VALUE_OFFSET) + 1n)
80
+ WasmI32.toGrain(ptr): Uint32
81
+ }
82
+
83
+ /**
84
+ * Decrements the value by one.
85
+ *
86
+ * @param value: The value to decrement
87
+ * @returns The decremented value
88
+ *
89
+ * @since v0.6.0
90
+ */
91
+ @unsafe
92
+ provide let decr = (value: Uint32) => {
93
+ let value = WasmI32.fromGrain(value)
94
+ let ptr = newUint32(WasmI32.load(value, _VALUE_OFFSET) - 1n)
95
+ WasmI32.toGrain(ptr): Uint32
96
+ }
97
+
98
+ /**
99
+ * Computes the sum of its operands.
100
+ *
101
+ * @param x: The first operand
102
+ * @param y: The second operand
103
+ * @returns The sum of the two operands
104
+ *
105
+ * @since v0.6.0
106
+ */
107
+ @unsafe
108
+ provide let (+) = (x: Uint32, y: Uint32) => {
109
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
110
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
111
+ let ptr = newUint32(xv + yv)
112
+ WasmI32.toGrain(ptr): Uint32
113
+ }
114
+
115
+ /**
116
+ * Computes the difference of its operands.
117
+ *
118
+ * @param x: The first operand
119
+ * @param y: The second operand
120
+ * @returns The difference of the two operands
121
+ *
122
+ * @since v0.6.0
123
+ */
124
+ @unsafe
125
+ provide let (-) = (x: Uint32, y: Uint32) => {
126
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
127
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
128
+ let ptr = newUint32(xv - yv)
129
+ WasmI32.toGrain(ptr): Uint32
130
+ }
131
+
132
+ /**
133
+ * Computes the product of its operands.
134
+ *
135
+ * @param x: The first operand
136
+ * @param y: The second operand
137
+ * @returns The product of the two operands
138
+ *
139
+ * @since v0.6.0
140
+ */
141
+ @unsafe
142
+ provide let (*) = (x: Uint32, y: Uint32) => {
143
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
144
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
145
+ let ptr = newUint32(xv * yv)
146
+ WasmI32.toGrain(ptr): Uint32
147
+ }
148
+
149
+ /**
150
+ * Computes the quotient of its operands.
151
+ *
152
+ * @param x: The first operand
153
+ * @param y: The second operand
154
+ * @returns The quotient of its operands
155
+ *
156
+ * @since v0.6.0
157
+ */
158
+ @unsafe
159
+ provide let (/) = (x: Uint32, y: Uint32) => {
160
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
161
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
162
+ let ptr = newUint32(WasmI32.divU(xv, yv))
163
+ WasmI32.toGrain(ptr): Uint32
164
+ }
165
+
166
+ /**
167
+ * Computes the remainder of the division of its operands.
168
+ *
169
+ * @param x: The first operand
170
+ * @param y: The second operand
171
+ * @returns The remainder of its operands
172
+ *
173
+ * @since v0.6.0
174
+ */
175
+ @unsafe
176
+ provide let rem = (x: Uint32, y: Uint32) => {
177
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
178
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
179
+ let ptr = newUint32(WasmI32.remU(xv, yv))
180
+ WasmI32.toGrain(ptr): Uint32
181
+ }
182
+
183
+ /**
184
+ * Rotates the bits of the value left by the given number of bits.
185
+ *
186
+ * @param value: The value to rotate
187
+ * @param amount: The number of bits to rotate by
188
+ * @returns The rotated value
189
+ *
190
+ * @since v0.6.0
191
+ */
192
+ @unsafe
193
+ provide let rotl = (value: Uint32, amount: Uint32) => {
194
+ let xv = WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET)
195
+ let yv = WasmI32.load(WasmI32.fromGrain(amount), _VALUE_OFFSET)
196
+ let ptr = newUint32(WasmI32.rotl(xv, yv))
197
+ WasmI32.toGrain(ptr): Uint32
198
+ }
199
+
200
+ /**
201
+ * Rotates the bits of the value right by the given number of bits.
202
+ *
203
+ * @param value: The value to rotate
204
+ * @param amount: The number of bits to rotate by
205
+ * @returns The rotated value
206
+ *
207
+ * @since v0.6.0
208
+ */
209
+ @unsafe
210
+ provide let rotr = (value: Uint32, amount: Uint32) => {
211
+ let xv = WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET)
212
+ let yv = WasmI32.load(WasmI32.fromGrain(amount), _VALUE_OFFSET)
213
+ let ptr = newUint32(WasmI32.rotr(xv, yv))
214
+ WasmI32.toGrain(ptr): Uint32
215
+ }
216
+
217
+ /**
218
+ * Shifts the bits of the value left by the given number of bits.
219
+ *
220
+ * @param value: The value to shift
221
+ * @param amount: The number of bits to shift by
222
+ * @returns The shifted value
223
+ *
224
+ * @since v0.6.0
225
+ */
226
+ @unsafe
227
+ provide let (<<) = (value: Uint32, amount: Uint32) => {
228
+ let xv = WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET)
229
+ let yv = WasmI32.load(WasmI32.fromGrain(amount), _VALUE_OFFSET)
230
+ let ptr = newUint32(xv << yv)
231
+ WasmI32.toGrain(ptr): Uint32
232
+ }
233
+
234
+ /**
235
+ * Shifts the bits of the value right by the given number of bits.
236
+ *
237
+ * @param value: The value to shift
238
+ * @param amount: The amount to shift by
239
+ * @returns The shifted value
240
+ *
241
+ * @since v0.6.0
242
+ */
243
+ @unsafe
244
+ provide let (>>>) = (value: Uint32, amount: Uint32) => {
245
+ let xv = WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET)
246
+ let yv = WasmI32.load(WasmI32.fromGrain(amount), _VALUE_OFFSET)
247
+ let ptr = newUint32(xv >>> yv)
248
+ WasmI32.toGrain(ptr): Uint32
249
+ }
250
+
251
+ /**
252
+ * Checks if the first value is equal to the second value.
253
+ *
254
+ * @param x: The first value
255
+ * @param y: The second value
256
+ * @returns `true` if the first value is equal to the second value or `false` otherwise
257
+ *
258
+ * @since v0.6.0
259
+ */
260
+ @unsafe
261
+ provide let (==) = (x: Uint32, y: Uint32) => {
262
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
263
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
264
+ xv == yv
265
+ }
266
+
267
+ /**
268
+ * Checks if the first value is not equal to the second value.
269
+ *
270
+ * @param x: The first value
271
+ * @param y: The second value
272
+ * @returns `true` if the first value is not equal to the second value or `false` otherwise
273
+ *
274
+ * @since v0.6.0
275
+ */
276
+ @unsafe
277
+ provide let (!=) = (x: Uint32, y: Uint32) => {
278
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
279
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
280
+ xv != yv
281
+ }
282
+
283
+ /**
284
+ * Checks if the given value is equal to zero.
285
+ *
286
+ * @param value: The value to inspect
287
+ * @returns `true` if the first value is equal to zero or `false` otherwise
288
+ *
289
+ * @since v0.6.0
290
+ */
291
+ @unsafe
292
+ provide let eqz = (value: Uint32) => {
293
+ let xv = WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET)
294
+ WasmI32.eqz(xv)
295
+ }
296
+
297
+ /**
298
+ * Checks if the first value is less than the second value.
299
+ *
300
+ * @param x: The first value
301
+ * @param y: The second value
302
+ * @returns `true` if the first value is less than the second value or `false` otherwise
303
+ *
304
+ * @since v0.6.0
305
+ */
306
+ @unsafe
307
+ provide let (<) = (x: Uint32, y: Uint32) => {
308
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
309
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
310
+ WasmI32.ltU(xv, yv)
311
+ }
312
+
313
+ /**
314
+ * Checks if the first value is greater than the second value.
315
+ *
316
+ * @param x: The first value
317
+ * @param y: The second value
318
+ * @returns `true` if the first value is greater than the second value or `false` otherwise
319
+ *
320
+ * @since v0.6.0
321
+ */
322
+ @unsafe
323
+ provide let (>) = (x: Uint32, y: Uint32) => {
324
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
325
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
326
+ WasmI32.gtU(xv, yv)
327
+ }
328
+
329
+ /**
330
+ * Checks if the first value is less than or equal to the second value.
331
+ *
332
+ * @param x: The first value
333
+ * @param y: The second value
334
+ * @returns `true` if the first value is less than or equal to the second value or `false` otherwise
335
+ *
336
+ * @since v0.6.0
337
+ */
338
+ @unsafe
339
+ provide let (<=) = (x: Uint32, y: Uint32) => {
340
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
341
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
342
+ WasmI32.leU(xv, yv)
343
+ }
344
+
345
+ /**
346
+ * Checks if the first value is greater than or equal to the second value.
347
+ *
348
+ * @param x: The first value
349
+ * @param y: The second value
350
+ * @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
351
+ *
352
+ * @since v0.6.0
353
+ */
354
+ @unsafe
355
+ provide let (>=) = (x: Uint32, y: Uint32) => {
356
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
357
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
358
+ WasmI32.geU(xv, yv)
359
+ }
360
+
361
+ /**
362
+ * Computes the bitwise NOT of the given value.
363
+ *
364
+ * @param value: The given value
365
+ * @returns Containing the inverted bits of the given value
366
+ *
367
+ * @since v0.6.0
368
+ */
369
+ @unsafe
370
+ provide let lnot = (value: Uint32) => {
371
+ let xv = WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET)
372
+ let ptr = newUint32(xv ^ 0xffffffffn)
373
+ WasmI32.toGrain(ptr): Uint32
374
+ }
375
+
376
+ /**
377
+ * Computes the bitwise AND (`&`) on the given operands.
378
+ *
379
+ * @param x: The first operand
380
+ * @param y: The second operand
381
+ * @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1`
382
+ *
383
+ * @since v0.6.0
384
+ */
385
+ @unsafe
386
+ provide let (&) = (x: Uint32, y: Uint32) => {
387
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
388
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
389
+ let ptr = newUint32(xv & yv)
390
+ WasmI32.toGrain(ptr): Uint32
391
+ }
392
+
393
+ /**
394
+ * Computes the bitwise OR (`|`) on the given operands.
395
+ *
396
+ * @param x: The first operand
397
+ * @param y: The second operand
398
+ * @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`
399
+ *
400
+ * @since v0.6.0
401
+ */
402
+ @unsafe
403
+ provide let (|) = (x: Uint32, y: Uint32) => {
404
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
405
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
406
+ let ptr = newUint32(xv | yv)
407
+ WasmI32.toGrain(ptr): Uint32
408
+ }
409
+
410
+ /**
411
+ * Computes the bitwise XOR (`^`) on the given operands.
412
+ *
413
+ * @param x: The first operand
414
+ * @param y: The second operand
415
+ * @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`
416
+ *
417
+ * @since v0.6.0
418
+ */
419
+ @unsafe
420
+ provide let (^) = (x: Uint32, y: Uint32) => {
421
+ let xv = WasmI32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
422
+ let yv = WasmI32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
423
+ let ptr = newUint32(xv ^ yv)
424
+ WasmI32.toGrain(ptr): Uint32
425
+ }
426
+
427
+ /**
428
+ * Counts the number of leading zero bits in the value.
429
+ *
430
+ * @param value: The value to inspect
431
+ * @returns The amount of leading zeros
432
+ *
433
+ * @since v0.6.0
434
+ */
435
+ @unsafe
436
+ provide let clz = (value: Uint32) => {
437
+ let nv = WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET)
438
+ let ptr = newUint32(WasmI32.clz(nv))
439
+ WasmI32.toGrain(ptr): Uint32
440
+ }
441
+
442
+ /**
443
+ * Counts the number of trailing zero bits in the value.
444
+ *
445
+ * @param value: The value to inspect
446
+ * @returns The amount of trailing zeros
447
+ *
448
+ * @since v0.6.0
449
+ */
450
+ @unsafe
451
+ provide let ctz = (value: Uint32) => {
452
+ let nv = WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET)
453
+ let ptr = newUint32(WasmI32.ctz(nv))
454
+ WasmI32.toGrain(ptr): Uint32
455
+ }
456
+
457
+ /**
458
+ * Counts the number of bits set to `1` in the value, also known as a population count.
459
+ *
460
+ * @param value: The value to inspect
461
+ * @returns The amount of 1-bits in its operand
462
+ *
463
+ * @since v0.6.0
464
+ */
465
+ @unsafe
466
+ provide let popcnt = (value: Uint32) => {
467
+ let nv = WasmI32.load(WasmI32.fromGrain(value), _VALUE_OFFSET)
468
+ let ptr = newUint32(WasmI32.popcnt(nv))
469
+ WasmI32.toGrain(ptr): Uint32
470
+ }