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