@grain/stdlib 0.4.4 → 0.5.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 +87 -0
- package/LICENSE +1 -1
- package/array.gr +92 -73
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +56 -217
- package/buffer.md +24 -17
- package/bytes.gr +103 -205
- package/bytes.md +19 -0
- package/char.gr +152 -166
- package/char.md +200 -0
- package/exception.md +6 -0
- package/float32.gr +159 -82
- package/float32.md +315 -0
- package/float64.gr +163 -82
- package/float64.md +315 -0
- package/hash.gr +53 -49
- package/int32.gr +479 -230
- package/int32.md +937 -0
- package/int64.gr +479 -230
- package/int64.md +937 -0
- package/list.gr +530 -116
- package/list.md +1141 -0
- package/map.gr +302 -121
- package/map.md +525 -0
- package/number.gr +51 -57
- package/number.md +37 -3
- package/option.gr +25 -25
- package/option.md +1 -1
- package/package.json +3 -3
- package/pervasives.gr +504 -52
- package/pervasives.md +1116 -0
- package/queue.gr +8 -1
- package/queue.md +10 -0
- package/random.gr +196 -0
- package/random.md +179 -0
- package/range.gr +26 -26
- package/regex.gr +1833 -842
- package/regex.md +11 -11
- package/result.md +1 -1
- package/runtime/bigint.gr +2045 -0
- package/runtime/bigint.md +326 -0
- package/runtime/dataStructures.gr +99 -279
- package/runtime/dataStructures.md +391 -0
- package/runtime/debug.gr +0 -1
- package/runtime/debug.md +6 -0
- package/runtime/equal.gr +40 -37
- package/runtime/equal.md +6 -0
- package/runtime/exception.gr +28 -15
- package/runtime/exception.md +30 -0
- package/runtime/gc.gr +50 -20
- package/runtime/gc.md +36 -0
- package/runtime/malloc.gr +32 -22
- package/runtime/malloc.md +55 -0
- package/runtime/numberUtils.gr +297 -142
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1204 -453
- package/runtime/numbers.md +300 -0
- package/runtime/string.gr +193 -228
- package/runtime/string.md +24 -0
- package/runtime/stringUtils.gr +62 -38
- package/runtime/stringUtils.md +6 -0
- package/runtime/unsafe/constants.gr +17 -0
- package/runtime/unsafe/constants.md +72 -0
- package/runtime/unsafe/conv.gr +10 -10
- package/runtime/unsafe/conv.md +71 -0
- package/runtime/unsafe/errors.md +204 -0
- package/runtime/unsafe/memory.gr +14 -3
- package/runtime/unsafe/memory.md +54 -0
- package/runtime/unsafe/printWasm.gr +4 -4
- package/runtime/unsafe/printWasm.md +24 -0
- package/runtime/unsafe/tags.gr +11 -10
- package/runtime/unsafe/tags.md +120 -0
- package/runtime/unsafe/wasmf32.gr +9 -2
- package/runtime/unsafe/wasmf32.md +168 -0
- package/runtime/unsafe/wasmf64.gr +9 -2
- package/runtime/unsafe/wasmf64.md +168 -0
- package/runtime/unsafe/wasmi32.gr +65 -47
- package/runtime/unsafe/wasmi32.md +282 -0
- package/runtime/unsafe/wasmi64.gr +78 -50
- package/runtime/unsafe/wasmi64.md +300 -0
- package/runtime/utils/printing.gr +62 -0
- package/runtime/utils/printing.md +18 -0
- package/runtime/wasi.gr +200 -46
- package/runtime/wasi.md +839 -0
- package/set.gr +125 -121
- package/set.md +24 -21
- package/stack.gr +29 -29
- package/stack.md +4 -6
- package/string.gr +434 -415
- package/string.md +3 -3
- package/sys/file.gr +477 -482
- package/sys/process.gr +33 -47
- package/sys/random.gr +48 -20
- package/sys/random.md +38 -0
- package/sys/time.gr +12 -28
package/int64.gr
CHANGED
|
@@ -1,132 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Int64: Utilities for working with the Int64 type.
|
|
3
|
+
* @example import Int64 from "int64"
|
|
4
|
+
*
|
|
5
|
+
* @since v0.2.0
|
|
6
|
+
*/
|
|
1
7
|
import WasmI32 from "runtime/unsafe/wasmi32"
|
|
2
8
|
import WasmI64 from "runtime/unsafe/wasmi64"
|
|
3
9
|
import Exception from "runtime/exception"
|
|
4
|
-
import Memory from "runtime/unsafe/memory"
|
|
5
10
|
|
|
6
|
-
import {
|
|
7
|
-
newInt64
|
|
8
|
-
} from "runtime/dataStructures"
|
|
11
|
+
import { newInt64 } from "runtime/dataStructures"
|
|
9
12
|
|
|
10
13
|
import {
|
|
11
14
|
coerceNumberToInt64 as fromNumber,
|
|
12
|
-
coerceInt64ToNumber as toNumber
|
|
15
|
+
coerceInt64ToNumber as toNumber,
|
|
13
16
|
} from "runtime/numbers"
|
|
14
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @section Conversions: Functions for converting between Numbers and the Int64 type.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Converts a Number to an Int64.
|
|
24
|
+
*
|
|
25
|
+
* @param number: The value to convert
|
|
26
|
+
* @returns The Number represented as an Int64
|
|
27
|
+
*
|
|
28
|
+
* @since v0.2.0
|
|
29
|
+
*/
|
|
15
30
|
export fromNumber
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Converts an Int64 to a Number.
|
|
34
|
+
*
|
|
35
|
+
* @param value: The value to convert
|
|
36
|
+
* @returns The Int64 represented as a Number
|
|
37
|
+
*
|
|
38
|
+
* @since v0.2.0
|
|
39
|
+
*/
|
|
16
40
|
export toNumber
|
|
17
41
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
/**
|
|
43
|
+
* @section Operations: Mathematical operations for Int64 values.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Increments the value by one.
|
|
48
|
+
*
|
|
49
|
+
* @param value: The value to increment
|
|
50
|
+
* @returns The incremented value
|
|
51
|
+
*
|
|
52
|
+
* @since v0.2.0
|
|
53
|
+
*/
|
|
54
|
+
@unsafe
|
|
55
|
+
export let incr = (value: Int64) => {
|
|
56
|
+
let value = WasmI32.fromGrain(value)
|
|
57
|
+
let ptr = newInt64(WasmI64.add(WasmI64.load(value, 8n), 1N))
|
|
58
|
+
WasmI32.toGrain(ptr): Int64
|
|
26
59
|
}
|
|
27
60
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Decrements the value by one.
|
|
63
|
+
*
|
|
64
|
+
* @param value: The value to decrement
|
|
65
|
+
* @returns The decremented value
|
|
66
|
+
*
|
|
67
|
+
* @since v0.2.0
|
|
68
|
+
*/
|
|
69
|
+
@unsafe
|
|
70
|
+
export let decr = (value: Int64) => {
|
|
71
|
+
let value = WasmI32.fromGrain(value)
|
|
72
|
+
let ptr = newInt64(WasmI64.sub(WasmI64.load(value, 8n), 1N))
|
|
73
|
+
WasmI32.toGrain(ptr): Int64
|
|
36
74
|
}
|
|
37
75
|
|
|
38
|
-
|
|
39
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Computes the sum of its operands.
|
|
78
|
+
*
|
|
79
|
+
* @param x: The first operand
|
|
80
|
+
* @param y: The second operand
|
|
81
|
+
* @returns The sum of the two operands
|
|
82
|
+
*
|
|
83
|
+
* @since v0.2.0
|
|
84
|
+
*/
|
|
85
|
+
@unsafe
|
|
86
|
+
export let add = (x: Int64, y: Int64) => {
|
|
40
87
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
41
88
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
42
89
|
let ptr = newInt64(WasmI64.add(xv, yv))
|
|
43
|
-
|
|
44
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
45
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
46
|
-
Memory.decRef(WasmI32.fromGrain(add))
|
|
47
|
-
ret
|
|
90
|
+
WasmI32.toGrain(ptr): Int64
|
|
48
91
|
}
|
|
49
92
|
|
|
50
|
-
|
|
51
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Computes the difference of its operands.
|
|
95
|
+
*
|
|
96
|
+
* @param x: The first operand
|
|
97
|
+
* @param y: The second operand
|
|
98
|
+
* @returns The difference of the two operands
|
|
99
|
+
*
|
|
100
|
+
* @since v0.2.0
|
|
101
|
+
*/
|
|
102
|
+
@unsafe
|
|
103
|
+
export let sub = (x: Int64, y: Int64) => {
|
|
52
104
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
53
105
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
54
106
|
let ptr = newInt64(WasmI64.sub(xv, yv))
|
|
55
|
-
|
|
56
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
57
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
58
|
-
Memory.decRef(WasmI32.fromGrain(sub))
|
|
59
|
-
ret
|
|
107
|
+
WasmI32.toGrain(ptr): Int64
|
|
60
108
|
}
|
|
61
109
|
|
|
62
|
-
|
|
63
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Computes the product of its operands.
|
|
112
|
+
*
|
|
113
|
+
* @param x: The first operand
|
|
114
|
+
* @param y: The second operand
|
|
115
|
+
* @returns The product of the two operands
|
|
116
|
+
*
|
|
117
|
+
* @since v0.2.0
|
|
118
|
+
*/
|
|
119
|
+
@unsafe
|
|
120
|
+
export let mul = (x: Int64, y: Int64) => {
|
|
64
121
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
65
122
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
66
123
|
let ptr = newInt64(WasmI64.mul(xv, yv))
|
|
67
|
-
|
|
68
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
69
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
70
|
-
Memory.decRef(WasmI32.fromGrain(mul))
|
|
71
|
-
ret
|
|
124
|
+
WasmI32.toGrain(ptr): Int64
|
|
72
125
|
}
|
|
73
126
|
|
|
74
|
-
|
|
75
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Computes the quotient of its operands using signed division.
|
|
129
|
+
*
|
|
130
|
+
* @param x: The first operand
|
|
131
|
+
* @param y: The second operand
|
|
132
|
+
* @returns The quotient of its operands
|
|
133
|
+
*
|
|
134
|
+
* @since v0.2.0
|
|
135
|
+
*/
|
|
136
|
+
@unsafe
|
|
137
|
+
export let div = (x: Int64, y: Int64) => {
|
|
76
138
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
77
139
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
78
140
|
let ptr = newInt64(WasmI64.divS(xv, yv))
|
|
79
|
-
|
|
80
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
81
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
82
|
-
Memory.decRef(WasmI32.fromGrain(div))
|
|
83
|
-
ret
|
|
141
|
+
WasmI32.toGrain(ptr): Int64
|
|
84
142
|
}
|
|
85
143
|
|
|
86
|
-
|
|
87
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Computes the quotient of its operands using unsigned division.
|
|
146
|
+
*
|
|
147
|
+
* @param x: The first operand
|
|
148
|
+
* @param y: The second operand
|
|
149
|
+
* @returns The quotient of its operands
|
|
150
|
+
*
|
|
151
|
+
* @since v0.2.0
|
|
152
|
+
*/
|
|
153
|
+
@unsafe
|
|
154
|
+
export let divU = (x: Int64, y: Int64) => {
|
|
88
155
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
89
156
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
90
157
|
let ptr = newInt64(WasmI64.divU(xv, yv))
|
|
91
|
-
|
|
92
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
93
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
94
|
-
Memory.decRef(WasmI32.fromGrain(divU))
|
|
95
|
-
ret
|
|
158
|
+
WasmI32.toGrain(ptr): Int64
|
|
96
159
|
}
|
|
97
160
|
|
|
98
|
-
|
|
99
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Computes the remainder of the division of its operands using signed division.
|
|
163
|
+
*
|
|
164
|
+
* @param x: The first operand
|
|
165
|
+
* @param y: The second operand
|
|
166
|
+
* @returns The remainder of its operands
|
|
167
|
+
*
|
|
168
|
+
* @since v0.2.0
|
|
169
|
+
*/
|
|
170
|
+
@unsafe
|
|
171
|
+
export let rem = (x: Int64, y: Int64) => {
|
|
100
172
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
101
173
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
102
174
|
let ptr = newInt64(WasmI64.remS(xv, yv))
|
|
103
|
-
|
|
104
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
105
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
106
|
-
Memory.decRef(WasmI32.fromGrain(rem))
|
|
107
|
-
ret
|
|
175
|
+
WasmI32.toGrain(ptr): Int64
|
|
108
176
|
}
|
|
109
177
|
|
|
110
|
-
|
|
111
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Computes the remainder of the division of its operands using unsigned division.
|
|
180
|
+
*
|
|
181
|
+
* @param x: The first operand
|
|
182
|
+
* @param y: The second operand
|
|
183
|
+
* @returns The remainder of its operands
|
|
184
|
+
*
|
|
185
|
+
* @since v0.2.0
|
|
186
|
+
*/
|
|
187
|
+
@unsafe
|
|
188
|
+
export let remU = (x: Int64, y: Int64) => {
|
|
112
189
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
113
190
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
114
191
|
let ptr = newInt64(WasmI64.remU(xv, yv))
|
|
115
|
-
|
|
116
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
117
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
118
|
-
Memory.decRef(WasmI32.fromGrain(remU))
|
|
119
|
-
ret
|
|
192
|
+
WasmI32.toGrain(ptr): Int64
|
|
120
193
|
}
|
|
121
194
|
|
|
122
|
-
@
|
|
123
|
-
let abs =
|
|
195
|
+
@unsafe
|
|
196
|
+
let abs = n => {
|
|
124
197
|
let mask = WasmI64.shrS(n, 63N)
|
|
125
198
|
WasmI64.sub(WasmI64.xor(n, mask), mask)
|
|
126
199
|
}
|
|
127
200
|
|
|
128
|
-
|
|
129
|
-
|
|
201
|
+
/**
|
|
202
|
+
* Computes the remainder of the division of the first operand by the second.
|
|
203
|
+
* The result will have the sign of the second operand.
|
|
204
|
+
*
|
|
205
|
+
* @param x: The first operand
|
|
206
|
+
* @param y: The second operand
|
|
207
|
+
* @returns The modulus of its operands
|
|
208
|
+
*
|
|
209
|
+
* @since v0.2.0
|
|
210
|
+
*/
|
|
211
|
+
@unsafe
|
|
212
|
+
export let mod = (x: Int64, y: Int64) => {
|
|
130
213
|
let xval = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
131
214
|
let yval = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
132
215
|
|
|
@@ -139,229 +222,395 @@ export let rec mod = (x: Int64, y: Int64) => {
|
|
|
139
222
|
let yabs = abs(yval)
|
|
140
223
|
let mval = WasmI64.remS(xabs, yabs)
|
|
141
224
|
let mres = WasmI64.sub(yabs, mval)
|
|
142
|
-
newInt64(
|
|
225
|
+
newInt64(
|
|
226
|
+
if (WasmI64.ne(mval, 0N)) (
|
|
227
|
+
if (WasmI64.ltS(yval, 0N)) WasmI64.sub(0N, mres) else mres
|
|
228
|
+
) else 0N
|
|
229
|
+
)
|
|
143
230
|
} else {
|
|
144
231
|
newInt64(WasmI64.remS(xval, yval))
|
|
145
232
|
}
|
|
146
|
-
|
|
147
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
148
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
149
|
-
Memory.decRef(WasmI32.fromGrain(mod))
|
|
150
|
-
ret
|
|
233
|
+
WasmI32.toGrain(ptr): Int64
|
|
151
234
|
}
|
|
152
235
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
236
|
+
/**
|
|
237
|
+
* @section Bitwise operations: Functions for operating on bits of Int64 values.
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Rotates the bits of the value left by the given number of bits.
|
|
242
|
+
*
|
|
243
|
+
* @param value: The value to rotate
|
|
244
|
+
* @param amount: The number of bits to rotate by
|
|
245
|
+
* @returns The rotated value
|
|
246
|
+
*
|
|
247
|
+
* @since v0.4.0
|
|
248
|
+
*/
|
|
249
|
+
@unsafe
|
|
250
|
+
export let rotl = (value: Int64, amount: Int64) => {
|
|
251
|
+
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
252
|
+
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
253
|
+
let ptr = newInt64(WasmI64.rotl(xv, yv))
|
|
254
|
+
WasmI32.toGrain(ptr): Int64
|
|
161
255
|
}
|
|
162
256
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Rotates the bits of the value right by the given number of bits.
|
|
259
|
+
*
|
|
260
|
+
* @param value: The value to rotate
|
|
261
|
+
* @param amount: The number of bits to rotate by
|
|
262
|
+
* @returns The rotated value
|
|
263
|
+
*
|
|
264
|
+
* @since v0.4.0
|
|
265
|
+
*/
|
|
266
|
+
@unsafe
|
|
267
|
+
export let rotr = (value: Int64, amount: Int64) => {
|
|
268
|
+
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
269
|
+
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
270
|
+
let ptr = newInt64(WasmI64.rotr(xv, yv))
|
|
271
|
+
WasmI32.toGrain(ptr): Int64
|
|
171
272
|
}
|
|
172
273
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
274
|
+
/**
|
|
275
|
+
* Shifts the bits of the value left by the given number of bits.
|
|
276
|
+
*
|
|
277
|
+
* @param value: The value to shift
|
|
278
|
+
* @param amount: The number of bits to shift by
|
|
279
|
+
* @returns The shifted value
|
|
280
|
+
*
|
|
281
|
+
* @since v0.2.0
|
|
282
|
+
*/
|
|
283
|
+
@unsafe
|
|
284
|
+
export let shl = (value: Int64, amount: Int64) => {
|
|
285
|
+
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
286
|
+
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
287
|
+
let ptr = newInt64(WasmI64.shl(xv, yv))
|
|
288
|
+
WasmI32.toGrain(ptr): Int64
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Shifts the bits of the value right by the given number of bits, preserving the sign bit.
|
|
293
|
+
*
|
|
294
|
+
* @param value: The value to shift
|
|
295
|
+
* @param amount: The amount to shift by
|
|
296
|
+
* @returns The shifted value
|
|
297
|
+
*
|
|
298
|
+
* @since v0.2.0
|
|
299
|
+
*/
|
|
300
|
+
@unsafe
|
|
301
|
+
export let shr = (value: Int64, amount: Int64) => {
|
|
302
|
+
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
303
|
+
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
304
|
+
let ptr = newInt64(WasmI64.shrS(xv, yv))
|
|
305
|
+
WasmI32.toGrain(ptr): Int64
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Shifts the bits of the value right by the given number of bits.
|
|
310
|
+
*
|
|
311
|
+
* @param value: The value to shift
|
|
312
|
+
* @param amount: The amount to shift by
|
|
313
|
+
* @returns The shifted value
|
|
314
|
+
*
|
|
315
|
+
* @since v0.2.0
|
|
316
|
+
*/
|
|
317
|
+
@unsafe
|
|
318
|
+
export let shrU = (value: Int64, amount: Int64) => {
|
|
319
|
+
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
320
|
+
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
321
|
+
let ptr = newInt64(WasmI64.shrU(xv, yv))
|
|
322
|
+
WasmI32.toGrain(ptr): Int64
|
|
181
323
|
}
|
|
182
324
|
|
|
183
|
-
|
|
184
|
-
|
|
325
|
+
/**
|
|
326
|
+
* @section Comparisons: Functions for comparing Int64 values.
|
|
327
|
+
*/
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Checks if the first value is 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 equal to the second value or `false` otherwise
|
|
335
|
+
*
|
|
336
|
+
* @since v0.4.0
|
|
337
|
+
*/
|
|
338
|
+
@unsafe
|
|
339
|
+
export let eq = (x: Int64, y: Int64) => {
|
|
185
340
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
186
341
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
187
|
-
|
|
188
|
-
let ret = WasmI32.toGrain(ptr): Int64
|
|
189
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
190
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
191
|
-
Memory.decRef(WasmI32.fromGrain(rotl))
|
|
192
|
-
ret
|
|
342
|
+
WasmI64.eq(xv, yv)
|
|
193
343
|
}
|
|
194
344
|
|
|
195
|
-
|
|
196
|
-
|
|
345
|
+
/**
|
|
346
|
+
* Checks if the first value is not 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 not equal to the second value or `false` otherwise
|
|
351
|
+
*
|
|
352
|
+
* @since v0.4.0
|
|
353
|
+
*/
|
|
354
|
+
@unsafe
|
|
355
|
+
export let ne = (x: Int64, y: Int64) => {
|
|
197
356
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
198
357
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
199
|
-
|
|
200
|
-
let ret = WasmI32.toGrain(ptr): Int64
|
|
201
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
202
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
203
|
-
Memory.decRef(WasmI32.fromGrain(rotr))
|
|
204
|
-
ret
|
|
358
|
+
WasmI64.ne(xv, yv)
|
|
205
359
|
}
|
|
206
360
|
|
|
207
|
-
|
|
361
|
+
/**
|
|
362
|
+
* Checks if the given value is equal to zero.
|
|
363
|
+
*
|
|
364
|
+
* @param value: The value to inspect
|
|
365
|
+
* @returns `true` if the first value is equal to zero or `false` otherwise
|
|
366
|
+
*
|
|
367
|
+
* @since v0.4.0
|
|
368
|
+
*/
|
|
369
|
+
@unsafe
|
|
370
|
+
export let eqz = (value: Int64) => {
|
|
371
|
+
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
372
|
+
WasmI64.eqz(xv)
|
|
373
|
+
}
|
|
208
374
|
|
|
209
|
-
|
|
210
|
-
|
|
375
|
+
/**
|
|
376
|
+
* Checks if the first value is less than the second value.
|
|
377
|
+
*
|
|
378
|
+
* @param x: The first value
|
|
379
|
+
* @param y: The second value
|
|
380
|
+
* @returns `true` if the first value is less than the second value or `false` otherwise
|
|
381
|
+
*
|
|
382
|
+
* @since v0.2.0
|
|
383
|
+
*/
|
|
384
|
+
@unsafe
|
|
385
|
+
export let lt = (x: Int64, y: Int64) => {
|
|
211
386
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
212
387
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
213
|
-
|
|
214
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
215
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
216
|
-
Memory.decRef(WasmI32.fromGrain(eq))
|
|
217
|
-
ret
|
|
388
|
+
WasmI64.ltS(xv, yv)
|
|
218
389
|
}
|
|
219
390
|
|
|
220
|
-
|
|
221
|
-
|
|
391
|
+
/**
|
|
392
|
+
* Checks if the first unsigned value is less than the second unsigned value.
|
|
393
|
+
*
|
|
394
|
+
* @param x: The first value
|
|
395
|
+
* @param y: The second value
|
|
396
|
+
* @returns `true` if the first value is less than the second value or `false` otherwise
|
|
397
|
+
*
|
|
398
|
+
* @since v0.5.0
|
|
399
|
+
*/
|
|
400
|
+
@unsafe
|
|
401
|
+
export let rec ltU = (x: Int64, y: Int64) => {
|
|
222
402
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
223
403
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
224
|
-
|
|
225
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
226
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
227
|
-
Memory.decRef(WasmI32.fromGrain(ne))
|
|
228
|
-
ret
|
|
404
|
+
WasmI64.ltU(xv, yv)
|
|
229
405
|
}
|
|
230
406
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Checks if the first value is greater than the second value.
|
|
409
|
+
*
|
|
410
|
+
* @param x: The first value
|
|
411
|
+
* @param y: The second value
|
|
412
|
+
* @returns `true` if the first value is greater than the second value or `false` otherwise
|
|
413
|
+
*
|
|
414
|
+
* @since v0.2.0
|
|
415
|
+
*/
|
|
416
|
+
@unsafe
|
|
417
|
+
export let gt = (x: Int64, y: Int64) => {
|
|
418
|
+
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
419
|
+
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
420
|
+
WasmI64.gtS(xv, yv)
|
|
238
421
|
}
|
|
239
422
|
|
|
240
|
-
|
|
241
|
-
|
|
423
|
+
/**
|
|
424
|
+
* Checks if the first unsigned value is greater than the second unsigned value.
|
|
425
|
+
*
|
|
426
|
+
* @param x: The first value
|
|
427
|
+
* @param y: The second value
|
|
428
|
+
* @returns `true` if the first value is greater than the second value or `false` otherwise
|
|
429
|
+
*
|
|
430
|
+
* @since v0.5.0
|
|
431
|
+
*/
|
|
432
|
+
@unsafe
|
|
433
|
+
export let rec gtU = (x: Int64, y: Int64) => {
|
|
242
434
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
243
435
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
244
|
-
|
|
245
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
246
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
247
|
-
Memory.decRef(WasmI32.fromGrain(lt))
|
|
248
|
-
ret
|
|
436
|
+
WasmI64.gtU(xv, yv)
|
|
249
437
|
}
|
|
250
438
|
|
|
251
|
-
|
|
252
|
-
|
|
439
|
+
/**
|
|
440
|
+
* Checks if the first value is less than or equal to the second value.
|
|
441
|
+
*
|
|
442
|
+
* @param x: The first value
|
|
443
|
+
* @param y: The second value
|
|
444
|
+
* @returns `true` if the first value is less than or equal to the second value or `false` otherwise
|
|
445
|
+
*
|
|
446
|
+
* @since v0.2.0
|
|
447
|
+
*/
|
|
448
|
+
@unsafe
|
|
449
|
+
export let lte = (x: Int64, y: Int64) => {
|
|
253
450
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
254
451
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
255
|
-
|
|
256
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
257
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
258
|
-
Memory.decRef(WasmI32.fromGrain(gt))
|
|
259
|
-
ret
|
|
452
|
+
WasmI64.leS(xv, yv)
|
|
260
453
|
}
|
|
261
454
|
|
|
262
|
-
|
|
263
|
-
|
|
455
|
+
/**
|
|
456
|
+
* Checks if the first unsigned value is less than or equal to the second unsigned value.
|
|
457
|
+
*
|
|
458
|
+
* @param x: The first value
|
|
459
|
+
* @param y: The second value
|
|
460
|
+
* @returns `true` if the first value is less than or equal to the second value or `false` otherwise
|
|
461
|
+
*
|
|
462
|
+
* @since v0.5.0
|
|
463
|
+
*/
|
|
464
|
+
@unsafe
|
|
465
|
+
export let rec lteU = (x: Int64, y: Int64) => {
|
|
264
466
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
265
467
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
266
|
-
|
|
267
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
268
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
269
|
-
Memory.decRef(WasmI32.fromGrain(lte))
|
|
270
|
-
ret
|
|
468
|
+
WasmI64.leU(xv, yv)
|
|
271
469
|
}
|
|
272
470
|
|
|
273
|
-
|
|
274
|
-
|
|
471
|
+
/**
|
|
472
|
+
* Checks if the first value is greater than or equal to the second value.
|
|
473
|
+
*
|
|
474
|
+
* @param x: The first value
|
|
475
|
+
* @param y: The second value
|
|
476
|
+
* @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
|
|
477
|
+
*
|
|
478
|
+
* @since v0.2.0
|
|
479
|
+
*/
|
|
480
|
+
@unsafe
|
|
481
|
+
export let gte = (x: Int64, y: Int64) => {
|
|
275
482
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
276
483
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
277
|
-
|
|
278
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
279
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
280
|
-
Memory.decRef(WasmI32.fromGrain(gte))
|
|
281
|
-
ret
|
|
484
|
+
WasmI64.geS(xv, yv)
|
|
282
485
|
}
|
|
283
486
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Checks if the first unsigned value is greater than or equal to the second unsigned value.
|
|
489
|
+
*
|
|
490
|
+
* @param x: The first value
|
|
491
|
+
* @param y: The second value
|
|
492
|
+
* @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
|
|
493
|
+
*
|
|
494
|
+
* @since v0.5.0
|
|
495
|
+
*/
|
|
496
|
+
@unsafe
|
|
497
|
+
export let rec gteU = (x: Int64, y: Int64) => {
|
|
287
498
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
288
|
-
let
|
|
289
|
-
|
|
290
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
291
|
-
Memory.decRef(WasmI32.fromGrain(lnot))
|
|
292
|
-
ret
|
|
499
|
+
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
500
|
+
WasmI64.geU(xv, yv)
|
|
293
501
|
}
|
|
294
502
|
|
|
503
|
+
/**
|
|
504
|
+
* @section Bitwise logic: Boolean operations on the bits of Int64 values.
|
|
505
|
+
*/
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Computes the bitwise NOT of the given value.
|
|
509
|
+
*
|
|
510
|
+
* @param value: The given value
|
|
511
|
+
* @returns Containing the inverted bits of the given value
|
|
512
|
+
*
|
|
513
|
+
* @since v0.2.0
|
|
514
|
+
*/
|
|
515
|
+
@unsafe
|
|
516
|
+
export let lnot = (value: Int64) => {
|
|
517
|
+
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
518
|
+
let ptr = newInt64(WasmI64.xor(xv, 0xffffffffffffffffN))
|
|
519
|
+
WasmI32.toGrain(ptr): Int64
|
|
520
|
+
}
|
|
295
521
|
|
|
296
|
-
|
|
297
|
-
|
|
522
|
+
/**
|
|
523
|
+
* Computes the bitwise AND (`&`) on the given operands.
|
|
524
|
+
*
|
|
525
|
+
* @param x: The first operand
|
|
526
|
+
* @param y: The second operand
|
|
527
|
+
* @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1`
|
|
528
|
+
*
|
|
529
|
+
* @since v0.2.0
|
|
530
|
+
*/
|
|
531
|
+
@unsafe
|
|
532
|
+
export let land = (x: Int64, y: Int64) => {
|
|
298
533
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
299
534
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
300
535
|
let ptr = newInt64(WasmI64.and(xv, yv))
|
|
301
|
-
|
|
302
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
303
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
304
|
-
Memory.decRef(WasmI32.fromGrain(land))
|
|
305
|
-
ret
|
|
536
|
+
WasmI32.toGrain(ptr): Int64
|
|
306
537
|
}
|
|
307
538
|
|
|
308
|
-
|
|
309
|
-
|
|
539
|
+
/**
|
|
540
|
+
* Computes the bitwise OR (`|`) on the given operands.
|
|
541
|
+
*
|
|
542
|
+
* @param x: The first operand
|
|
543
|
+
* @param y: The second operand
|
|
544
|
+
* @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`
|
|
545
|
+
*
|
|
546
|
+
* @since v0.2.0
|
|
547
|
+
*/
|
|
548
|
+
@unsafe
|
|
549
|
+
export let lor = (x: Int64, y: Int64) => {
|
|
310
550
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
311
551
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
312
552
|
let ptr = newInt64(WasmI64.or(xv, yv))
|
|
313
|
-
|
|
314
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
315
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
316
|
-
Memory.decRef(WasmI32.fromGrain(lor))
|
|
317
|
-
ret
|
|
553
|
+
WasmI32.toGrain(ptr): Int64
|
|
318
554
|
}
|
|
319
555
|
|
|
320
|
-
|
|
321
|
-
|
|
556
|
+
/**
|
|
557
|
+
* Computes the bitwise XOR (`^`) on the given operands.
|
|
558
|
+
*
|
|
559
|
+
* @param x: The first operand
|
|
560
|
+
* @param y: The second operand
|
|
561
|
+
* @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`
|
|
562
|
+
*
|
|
563
|
+
* @since v0.2.0
|
|
564
|
+
*/
|
|
565
|
+
@unsafe
|
|
566
|
+
export let lxor = (x: Int64, y: Int64) => {
|
|
322
567
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
323
568
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
324
569
|
let ptr = newInt64(WasmI64.xor(xv, yv))
|
|
325
|
-
|
|
326
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
327
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
328
|
-
Memory.decRef(WasmI32.fromGrain(lxor))
|
|
329
|
-
ret
|
|
570
|
+
WasmI32.toGrain(ptr): Int64
|
|
330
571
|
}
|
|
331
572
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
573
|
+
/**
|
|
574
|
+
* Counts the number of leading zero bits in the value.
|
|
575
|
+
*
|
|
576
|
+
* @param value: The value to inspect
|
|
577
|
+
* @returns The amount of leading zeros
|
|
578
|
+
*
|
|
579
|
+
* @since v0.4.0
|
|
580
|
+
*/
|
|
581
|
+
@unsafe
|
|
582
|
+
export let clz = (value: Int64) => {
|
|
583
|
+
let nv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
584
|
+
let ptr = newInt64(WasmI64.clz(nv))
|
|
585
|
+
WasmI32.toGrain(ptr): Int64
|
|
343
586
|
}
|
|
344
587
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
588
|
+
/**
|
|
589
|
+
* Counts the number of trailing zero bits in the value.
|
|
590
|
+
*
|
|
591
|
+
* @param value: The value to inspect
|
|
592
|
+
* @returns The amount of trailing zeros
|
|
593
|
+
*
|
|
594
|
+
* @since v0.4.0
|
|
595
|
+
*/
|
|
596
|
+
@unsafe
|
|
597
|
+
export let ctz = (value: Int64) => {
|
|
598
|
+
let nv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
599
|
+
let ptr = newInt64(WasmI64.ctz(nv))
|
|
600
|
+
WasmI32.toGrain(ptr): Int64
|
|
355
601
|
}
|
|
356
602
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
603
|
+
/**
|
|
604
|
+
* Counts the number of bits set to `1` in the value, also known as a population count.
|
|
605
|
+
*
|
|
606
|
+
* @param value: The value to inspect
|
|
607
|
+
* @returns The amount of 1-bits in its operand
|
|
608
|
+
*
|
|
609
|
+
* @since v0.4.0
|
|
610
|
+
*/
|
|
611
|
+
@unsafe
|
|
612
|
+
export let popcnt = (value: Int64) => {
|
|
613
|
+
let nv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
614
|
+
let ptr = newInt64(WasmI64.popcnt(nv))
|
|
615
|
+
WasmI32.toGrain(ptr): Int64
|
|
367
616
|
}
|