@fluffylabs/anan-as 1.2.0 → 1.3.0-39d3435
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/dist/bin/index.js +138 -5
- package/dist/bin/src/fuzz.js +2 -2
- package/dist/bin/src/test-json.js +2 -6
- package/dist/bin/src/trace-parse.js +1 -0
- package/dist/bin/src/trace-replay.js +14 -9
- package/dist/bin/src/tracer.js +16 -13
- package/dist/bin/src/utils.js +2 -2
- package/dist/build/compiler-inline.js +1 -1
- package/dist/build/compiler.d.ts +17 -13
- package/dist/build/compiler.js +13 -21
- package/dist/build/compiler.wasm +0 -0
- package/dist/build/debug-inline.js +1 -1
- package/dist/build/debug-raw-inline.js +1 -1
- package/dist/build/debug-raw.d.ts +50 -112
- package/dist/build/debug-raw.js +78 -139
- package/dist/build/debug-raw.wasm +0 -0
- package/dist/build/debug.d.ts +50 -112
- package/dist/build/debug.js +81 -147
- package/dist/build/debug.wasm +0 -0
- package/dist/build/js/assembly/api-debugger.d.ts +55 -0
- package/dist/build/js/assembly/api-debugger.js +245 -0
- package/dist/build/js/assembly/api-internal.d.ts +13 -0
- package/dist/build/js/assembly/api-internal.js +191 -0
- package/dist/build/js/assembly/api-types.d.ts +45 -0
- package/dist/build/js/assembly/api-types.js +52 -0
- package/dist/build/js/assembly/api-utils.d.ts +79 -0
- package/dist/build/js/assembly/api-utils.js +221 -0
- package/dist/build/js/assembly/arguments.d.ts +44 -0
- package/dist/build/js/assembly/arguments.js +164 -0
- package/dist/build/js/assembly/codec.d.ts +24 -0
- package/dist/build/js/assembly/codec.js +139 -0
- package/dist/build/js/assembly/gas.d.ts +11 -0
- package/dist/build/js/assembly/gas.js +33 -0
- package/dist/build/js/assembly/index-shared.d.ts +4 -0
- package/dist/build/js/assembly/index-shared.js +4 -0
- package/dist/build/js/assembly/instructions/bit.d.ts +11 -0
- package/dist/build/js/assembly/instructions/bit.js +53 -0
- package/dist/build/js/assembly/instructions/branch.d.ts +17 -0
- package/dist/build/js/assembly/instructions/branch.js +120 -0
- package/dist/build/js/assembly/instructions/jump.d.ts +5 -0
- package/dist/build/js/assembly/instructions/jump.js +21 -0
- package/dist/build/js/assembly/instructions/load.d.ts +17 -0
- package/dist/build/js/assembly/instructions/load.js +134 -0
- package/dist/build/js/assembly/instructions/logic.d.ts +10 -0
- package/dist/build/js/assembly/instructions/logic.js +47 -0
- package/dist/build/js/assembly/instructions/math.d.ts +28 -0
- package/dist/build/js/assembly/instructions/math.js +225 -0
- package/dist/build/js/assembly/instructions/misc.d.ts +6 -0
- package/dist/build/js/assembly/instructions/misc.js +22 -0
- package/dist/build/js/assembly/instructions/mov.d.ts +6 -0
- package/dist/build/js/assembly/instructions/mov.js +35 -0
- package/dist/build/js/assembly/instructions/outcome.d.ts +30 -0
- package/dist/build/js/assembly/instructions/outcome.js +88 -0
- package/dist/build/js/assembly/instructions/rot.d.ts +15 -0
- package/dist/build/js/assembly/instructions/rot.js +66 -0
- package/dist/build/js/assembly/instructions/set.d.ts +7 -0
- package/dist/build/js/assembly/instructions/set.js +36 -0
- package/dist/build/js/assembly/instructions/shift.d.ts +19 -0
- package/dist/build/js/assembly/instructions/shift.js +121 -0
- package/dist/build/js/assembly/instructions/store.d.ts +17 -0
- package/dist/build/js/assembly/instructions/store.js +101 -0
- package/dist/build/js/assembly/instructions/utils.d.ts +25 -0
- package/dist/build/js/assembly/instructions/utils.js +91 -0
- package/dist/build/js/assembly/instructions-exe.d.ts +2 -0
- package/dist/build/js/assembly/instructions-exe.js +245 -0
- package/dist/build/js/assembly/instructions.d.ts +10 -0
- package/dist/build/js/assembly/instructions.js +252 -0
- package/dist/build/js/assembly/interpreter.d.ts +28 -0
- package/dist/build/js/assembly/interpreter.js +221 -0
- package/dist/build/js/assembly/math.d.ts +6 -0
- package/dist/build/js/assembly/math.js +22 -0
- package/dist/build/js/assembly/memory-page.d.ts +36 -0
- package/dist/build/js/assembly/memory-page.js +74 -0
- package/dist/build/js/assembly/memory.d.ts +83 -0
- package/dist/build/js/assembly/memory.js +482 -0
- package/dist/build/js/assembly/portable.d.ts +24 -0
- package/dist/build/js/assembly/portable.js +363 -0
- package/dist/build/js/assembly/program-build.d.ts +2 -0
- package/dist/build/js/assembly/program-build.js +104 -0
- package/dist/build/js/assembly/program.d.ts +85 -0
- package/dist/build/js/assembly/program.js +340 -0
- package/dist/build/js/assembly/registers.d.ts +6 -0
- package/dist/build/js/assembly/registers.js +9 -0
- package/dist/build/js/assembly/spi.d.ts +92 -0
- package/dist/build/js/assembly/spi.js +152 -0
- package/dist/build/js/portable/bootstrap.d.ts +1 -0
- package/dist/build/js/portable/bootstrap.js +6 -0
- package/dist/build/js/portable/index.d.ts +4 -0
- package/dist/build/js/portable/index.js +6 -0
- package/dist/build/js/portable-bundle.js +4497 -0
- package/dist/build/release-inline.js +1 -1
- package/dist/build/release-mini-inline.js +1 -1
- package/dist/build/release-mini.d.ts +50 -112
- package/dist/build/release-mini.js +81 -147
- package/dist/build/release-mini.wasm +0 -0
- package/dist/build/release-stub-inline.js +1 -1
- package/dist/build/release-stub.d.ts +50 -112
- package/dist/build/release-stub.js +81 -147
- package/dist/build/release-stub.wasm +0 -0
- package/dist/build/release.d.ts +50 -112
- package/dist/build/release.js +81 -147
- package/dist/build/release.wasm +0 -0
- package/dist/build/test-inline.js +1 -1
- package/dist/build/test.wasm +0 -0
- package/dist/test/test-gas-cost.js +2 -3
- package/dist/test/test-trace-format.js +166 -0
- package/dist/test/test-w3f-common.js +125 -0
- package/dist/test/test-w3f-portable.js +5 -0
- package/dist/test/test-w3f.js +3 -120
- package/package.json +22 -11
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { portable } from "../portable";
|
|
2
|
+
import { OutcomeData } from "./outcome";
|
|
3
|
+
import { Inst } from "./utils";
|
|
4
|
+
// COUNT_SET_BITS_64
|
|
5
|
+
export const count_set_bits_64 = (r, args, regs) => {
|
|
6
|
+
regs[Inst.reg(args.b)] = portable.popcnt_u64(regs[Inst.reg(args.a)]);
|
|
7
|
+
return OutcomeData.ok(r);
|
|
8
|
+
};
|
|
9
|
+
// COUNT_SET_BITS_32
|
|
10
|
+
export const count_set_bits_32 = (r, args, regs) => {
|
|
11
|
+
regs[Inst.reg(args.b)] = u64(portable.popcnt_u32(u32(regs[Inst.reg(args.a)])));
|
|
12
|
+
return OutcomeData.ok(r);
|
|
13
|
+
};
|
|
14
|
+
// LEADING_ZERO_BITS_64
|
|
15
|
+
export const leading_zero_bits_64 = (r, args, regs) => {
|
|
16
|
+
regs[Inst.reg(args.b)] = portable.clz_u64(regs[Inst.reg(args.a)]);
|
|
17
|
+
return OutcomeData.ok(r);
|
|
18
|
+
};
|
|
19
|
+
// LEADING_ZERO_BITS_32
|
|
20
|
+
export const leading_zero_bits_32 = (r, args, regs) => {
|
|
21
|
+
regs[Inst.reg(args.b)] = u64(portable.clz_u32(u32(regs[Inst.reg(args.a)])));
|
|
22
|
+
return OutcomeData.ok(r);
|
|
23
|
+
};
|
|
24
|
+
// TRAILING_ZERO_BITS_64
|
|
25
|
+
export const trailing_zero_bits_64 = (r, args, regs) => {
|
|
26
|
+
regs[Inst.reg(args.b)] = portable.ctz_u64(regs[Inst.reg(args.a)]);
|
|
27
|
+
return OutcomeData.ok(r);
|
|
28
|
+
};
|
|
29
|
+
// TRAILING_ZERO_BITS_32
|
|
30
|
+
export const trailing_zero_bits_32 = (r, args, regs) => {
|
|
31
|
+
regs[Inst.reg(args.b)] = u64(portable.ctz_u32(u32(regs[Inst.reg(args.a)])));
|
|
32
|
+
return OutcomeData.ok(r);
|
|
33
|
+
};
|
|
34
|
+
// SIGN_EXTEND_8
|
|
35
|
+
export const sign_extend_8 = (r, args, regs) => {
|
|
36
|
+
regs[Inst.reg(args.b)] = Inst.u8SignExtend(u8(regs[Inst.reg(args.a)]));
|
|
37
|
+
return OutcomeData.ok(r);
|
|
38
|
+
};
|
|
39
|
+
// SIGN_EXTEND_16
|
|
40
|
+
export const sign_extend_16 = (r, args, regs) => {
|
|
41
|
+
regs[Inst.reg(args.b)] = Inst.u16SignExtend(u16(regs[Inst.reg(args.a)]));
|
|
42
|
+
return OutcomeData.ok(r);
|
|
43
|
+
};
|
|
44
|
+
// ZERO_EXTEND_16
|
|
45
|
+
export const zero_extend_16 = (r, args, regs) => {
|
|
46
|
+
regs[Inst.reg(args.b)] = u64(u16(regs[Inst.reg(args.a)]));
|
|
47
|
+
return OutcomeData.ok(r);
|
|
48
|
+
};
|
|
49
|
+
// REVERSE_BYTES
|
|
50
|
+
export const reverse_bytes = (r, args, regs) => {
|
|
51
|
+
regs[Inst.reg(args.b)] = portable.bswap_u64(regs[Inst.reg(args.a)]);
|
|
52
|
+
return OutcomeData.ok(r);
|
|
53
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InstructionRun } from "./outcome";
|
|
2
|
+
export declare const branch_eq_imm: InstructionRun;
|
|
3
|
+
export declare const branch_ne_imm: InstructionRun;
|
|
4
|
+
export declare const branch_lt_u_imm: InstructionRun;
|
|
5
|
+
export declare const branch_le_u_imm: InstructionRun;
|
|
6
|
+
export declare const branch_ge_u_imm: InstructionRun;
|
|
7
|
+
export declare const branch_gt_u_imm: InstructionRun;
|
|
8
|
+
export declare const branch_lt_s_imm: InstructionRun;
|
|
9
|
+
export declare const branch_le_s_imm: InstructionRun;
|
|
10
|
+
export declare const branch_ge_s_imm: InstructionRun;
|
|
11
|
+
export declare const branch_gt_s_imm: InstructionRun;
|
|
12
|
+
export declare const branch_eq: InstructionRun;
|
|
13
|
+
export declare const branch_ne: InstructionRun;
|
|
14
|
+
export declare const branch_lt_u: InstructionRun;
|
|
15
|
+
export declare const branch_lt_s: InstructionRun;
|
|
16
|
+
export declare const branch_ge_u: InstructionRun;
|
|
17
|
+
export declare const branch_ge_s: InstructionRun;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { OutcomeData } from "./outcome";
|
|
2
|
+
import { Inst } from "./utils";
|
|
3
|
+
// BRANCH_EQ_IMM
|
|
4
|
+
export const branch_eq_imm = (r, args, registers) => {
|
|
5
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
6
|
+
if (registers[Inst.reg(args.a)] === b) {
|
|
7
|
+
return OutcomeData.staticJump(r, args.c);
|
|
8
|
+
}
|
|
9
|
+
return OutcomeData.ok(r);
|
|
10
|
+
};
|
|
11
|
+
// BRANCH_NE_IMM
|
|
12
|
+
export const branch_ne_imm = (r, args, registers) => {
|
|
13
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
14
|
+
if (registers[Inst.reg(args.a)] !== b) {
|
|
15
|
+
return OutcomeData.staticJump(r, args.c);
|
|
16
|
+
}
|
|
17
|
+
return OutcomeData.ok(r);
|
|
18
|
+
};
|
|
19
|
+
// BRANCH_LT_U_IMM
|
|
20
|
+
export const branch_lt_u_imm = (r, args, registers) => {
|
|
21
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
22
|
+
if (registers[Inst.reg(args.a)] < b) {
|
|
23
|
+
return OutcomeData.staticJump(r, args.c);
|
|
24
|
+
}
|
|
25
|
+
return OutcomeData.ok(r);
|
|
26
|
+
};
|
|
27
|
+
// BRANCH_LE_U_IMM
|
|
28
|
+
export const branch_le_u_imm = (r, args, registers) => {
|
|
29
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
30
|
+
if (registers[Inst.reg(args.a)] <= b) {
|
|
31
|
+
return OutcomeData.staticJump(r, args.c);
|
|
32
|
+
}
|
|
33
|
+
return OutcomeData.ok(r);
|
|
34
|
+
};
|
|
35
|
+
// BRANCH_GE_U_IMM
|
|
36
|
+
export const branch_ge_u_imm = (r, args, registers) => {
|
|
37
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
38
|
+
if (registers[Inst.reg(args.a)] >= b) {
|
|
39
|
+
return OutcomeData.staticJump(r, args.c);
|
|
40
|
+
}
|
|
41
|
+
return OutcomeData.ok(r);
|
|
42
|
+
};
|
|
43
|
+
// BRANCH_GT_U_IMM
|
|
44
|
+
export const branch_gt_u_imm = (r, args, registers) => {
|
|
45
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
46
|
+
if (registers[Inst.reg(args.a)] > b) {
|
|
47
|
+
return OutcomeData.staticJump(r, args.c);
|
|
48
|
+
}
|
|
49
|
+
return OutcomeData.ok(r);
|
|
50
|
+
};
|
|
51
|
+
// BRANCH_LT_S_IMM
|
|
52
|
+
export const branch_lt_s_imm = (r, args, registers) => {
|
|
53
|
+
if (i64(registers[Inst.reg(args.a)]) < i64(Inst.u32SignExtend(args.b))) {
|
|
54
|
+
return OutcomeData.staticJump(r, args.c);
|
|
55
|
+
}
|
|
56
|
+
return OutcomeData.ok(r);
|
|
57
|
+
};
|
|
58
|
+
// BRANCH_LE_S_IMM
|
|
59
|
+
export const branch_le_s_imm = (r, args, registers) => {
|
|
60
|
+
if (i64(registers[Inst.reg(args.a)]) <= i64(Inst.u32SignExtend(args.b))) {
|
|
61
|
+
return OutcomeData.staticJump(r, args.c);
|
|
62
|
+
}
|
|
63
|
+
return OutcomeData.ok(r);
|
|
64
|
+
};
|
|
65
|
+
// BRANCH_GE_S_IMM
|
|
66
|
+
export const branch_ge_s_imm = (r, args, registers) => {
|
|
67
|
+
if (i64(registers[Inst.reg(args.a)]) >= i64(Inst.u32SignExtend(args.b))) {
|
|
68
|
+
return OutcomeData.staticJump(r, args.c);
|
|
69
|
+
}
|
|
70
|
+
return OutcomeData.ok(r);
|
|
71
|
+
};
|
|
72
|
+
// BRANCH_GT_S_IMM
|
|
73
|
+
export const branch_gt_s_imm = (r, args, registers) => {
|
|
74
|
+
if (i64(registers[Inst.reg(args.a)]) > i64(Inst.u32SignExtend(args.b))) {
|
|
75
|
+
return OutcomeData.staticJump(r, args.c);
|
|
76
|
+
}
|
|
77
|
+
return OutcomeData.ok(r);
|
|
78
|
+
};
|
|
79
|
+
// BRANCH_EQ
|
|
80
|
+
export const branch_eq = (r, args, registers) => {
|
|
81
|
+
if (registers[Inst.reg(args.a)] === registers[Inst.reg(args.b)]) {
|
|
82
|
+
return OutcomeData.staticJump(r, args.c);
|
|
83
|
+
}
|
|
84
|
+
return OutcomeData.ok(r);
|
|
85
|
+
};
|
|
86
|
+
// BRANCH_NE
|
|
87
|
+
export const branch_ne = (r, args, registers) => {
|
|
88
|
+
if (registers[Inst.reg(args.a)] !== registers[Inst.reg(args.b)]) {
|
|
89
|
+
return OutcomeData.staticJump(r, args.c);
|
|
90
|
+
}
|
|
91
|
+
return OutcomeData.ok(r);
|
|
92
|
+
};
|
|
93
|
+
// BRANCH_LT_U
|
|
94
|
+
export const branch_lt_u = (r, args, registers) => {
|
|
95
|
+
if (registers[Inst.reg(args.b)] < registers[Inst.reg(args.a)]) {
|
|
96
|
+
return OutcomeData.staticJump(r, args.c);
|
|
97
|
+
}
|
|
98
|
+
return OutcomeData.ok(r);
|
|
99
|
+
};
|
|
100
|
+
// BRANCH_LT_S
|
|
101
|
+
export const branch_lt_s = (r, args, registers) => {
|
|
102
|
+
if (i64(registers[Inst.reg(args.b)]) < i64(registers[Inst.reg(args.a)])) {
|
|
103
|
+
return OutcomeData.staticJump(r, args.c);
|
|
104
|
+
}
|
|
105
|
+
return OutcomeData.ok(r);
|
|
106
|
+
};
|
|
107
|
+
// BRANCH_GE_U
|
|
108
|
+
export const branch_ge_u = (r, args, registers) => {
|
|
109
|
+
if (registers[Inst.reg(args.b)] >= registers[Inst.reg(args.a)]) {
|
|
110
|
+
return OutcomeData.staticJump(r, args.c);
|
|
111
|
+
}
|
|
112
|
+
return OutcomeData.ok(r);
|
|
113
|
+
};
|
|
114
|
+
// BRANCH_GE_S
|
|
115
|
+
export const branch_ge_s = (r, args, registers) => {
|
|
116
|
+
if (i64(registers[Inst.reg(args.b)]) >= i64(registers[Inst.reg(args.a)])) {
|
|
117
|
+
return OutcomeData.staticJump(r, args.c);
|
|
118
|
+
}
|
|
119
|
+
return OutcomeData.ok(r);
|
|
120
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { portable } from "../portable";
|
|
2
|
+
import { OutcomeData } from "./outcome";
|
|
3
|
+
import { Inst } from "./utils";
|
|
4
|
+
// JUMP
|
|
5
|
+
export const jump = (r, args) => OutcomeData.staticJump(r, args.a);
|
|
6
|
+
// JUMP_IND
|
|
7
|
+
export const jump_ind = (r, args, registers) => {
|
|
8
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.b)));
|
|
9
|
+
return OutcomeData.dJump(r, address);
|
|
10
|
+
};
|
|
11
|
+
// LOAD_IMM_JUMP
|
|
12
|
+
export const load_imm_jump = (r, args, registers) => {
|
|
13
|
+
registers[Inst.reg(args.a)] = Inst.u32SignExtend(args.b);
|
|
14
|
+
return OutcomeData.staticJump(r, args.c);
|
|
15
|
+
};
|
|
16
|
+
// LOAD_IMM_JUMP_IND
|
|
17
|
+
export const load_imm_jump_ind = (r, args, registers) => {
|
|
18
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.d)));
|
|
19
|
+
registers[Inst.reg(args.b)] = Inst.u32SignExtend(args.c);
|
|
20
|
+
return OutcomeData.dJump(r, address);
|
|
21
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InstructionRun } from "./outcome";
|
|
2
|
+
export declare const load_imm_64: InstructionRun;
|
|
3
|
+
export declare const load_imm: InstructionRun;
|
|
4
|
+
export declare const load_u8: InstructionRun;
|
|
5
|
+
export declare const load_i8: InstructionRun;
|
|
6
|
+
export declare const load_u16: InstructionRun;
|
|
7
|
+
export declare const load_i16: InstructionRun;
|
|
8
|
+
export declare const load_u32: InstructionRun;
|
|
9
|
+
export declare const load_i32: InstructionRun;
|
|
10
|
+
export declare const load_u64: InstructionRun;
|
|
11
|
+
export declare const load_ind_u8: InstructionRun;
|
|
12
|
+
export declare const load_ind_i8: InstructionRun;
|
|
13
|
+
export declare const load_ind_u16: InstructionRun;
|
|
14
|
+
export declare const load_ind_i16: InstructionRun;
|
|
15
|
+
export declare const load_ind_u32: InstructionRun;
|
|
16
|
+
export declare const load_ind_i32: InstructionRun;
|
|
17
|
+
export declare const load_ind_u64: InstructionRun;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { MaybePageFault } from "../memory";
|
|
2
|
+
import { portable } from "../portable";
|
|
3
|
+
import { OutcomeData } from "./outcome";
|
|
4
|
+
import { Inst } from "./utils";
|
|
5
|
+
const faultRes = new MaybePageFault();
|
|
6
|
+
// LOAD_IMM_64
|
|
7
|
+
export const load_imm_64 = (r, args, registers) => {
|
|
8
|
+
registers[Inst.reg(args.a)] = portable.u64_add(u64(args.b), u64(args.c) << u64(32));
|
|
9
|
+
return OutcomeData.ok(r);
|
|
10
|
+
};
|
|
11
|
+
// LOAD_IMM
|
|
12
|
+
export const load_imm = (r, args, registers) => {
|
|
13
|
+
registers[Inst.reg(args.a)] = Inst.u32SignExtend(args.b);
|
|
14
|
+
return OutcomeData.ok(r);
|
|
15
|
+
};
|
|
16
|
+
// LOAD_U8
|
|
17
|
+
export const load_u8 = (r, args, registers, memory) => {
|
|
18
|
+
const result = memory.getU8(faultRes, args.b);
|
|
19
|
+
if (!faultRes.isFault) {
|
|
20
|
+
registers[Inst.reg(args.a)] = result;
|
|
21
|
+
}
|
|
22
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
23
|
+
};
|
|
24
|
+
// LOAD_I8
|
|
25
|
+
export const load_i8 = (r, args, registers, memory) => {
|
|
26
|
+
const result = memory.getI8(faultRes, args.b);
|
|
27
|
+
if (!faultRes.isFault) {
|
|
28
|
+
registers[Inst.reg(args.a)] = result;
|
|
29
|
+
}
|
|
30
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
31
|
+
};
|
|
32
|
+
// LOAD_U16
|
|
33
|
+
export const load_u16 = (r, args, registers, memory) => {
|
|
34
|
+
const result = memory.getU16(faultRes, args.b);
|
|
35
|
+
if (!faultRes.isFault) {
|
|
36
|
+
registers[Inst.reg(args.a)] = result;
|
|
37
|
+
}
|
|
38
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
39
|
+
};
|
|
40
|
+
// LOAD_I16
|
|
41
|
+
export const load_i16 = (r, args, registers, memory) => {
|
|
42
|
+
const result = memory.getI16(faultRes, args.b);
|
|
43
|
+
if (!faultRes.isFault) {
|
|
44
|
+
registers[Inst.reg(args.a)] = result;
|
|
45
|
+
}
|
|
46
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
47
|
+
};
|
|
48
|
+
// LOAD_U32
|
|
49
|
+
export const load_u32 = (r, args, registers, memory) => {
|
|
50
|
+
const result = memory.getU32(faultRes, args.b);
|
|
51
|
+
if (!faultRes.isFault) {
|
|
52
|
+
registers[Inst.reg(args.a)] = result;
|
|
53
|
+
}
|
|
54
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
55
|
+
};
|
|
56
|
+
// LOAD_I32
|
|
57
|
+
export const load_i32 = (r, args, registers, memory) => {
|
|
58
|
+
const result = memory.getI32(faultRes, args.b);
|
|
59
|
+
if (!faultRes.isFault) {
|
|
60
|
+
registers[Inst.reg(args.a)] = result;
|
|
61
|
+
}
|
|
62
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
63
|
+
};
|
|
64
|
+
// LOAD_U64
|
|
65
|
+
export const load_u64 = (r, args, registers, memory) => {
|
|
66
|
+
const result = memory.getU64(faultRes, args.b);
|
|
67
|
+
if (!faultRes.isFault) {
|
|
68
|
+
registers[Inst.reg(args.a)] = result;
|
|
69
|
+
}
|
|
70
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
71
|
+
};
|
|
72
|
+
// LOAD_IND_U8
|
|
73
|
+
export const load_ind_u8 = (r, args, registers, memory) => {
|
|
74
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.c)));
|
|
75
|
+
const result = memory.getU8(faultRes, address);
|
|
76
|
+
if (!faultRes.isFault) {
|
|
77
|
+
registers[Inst.reg(args.b)] = result;
|
|
78
|
+
}
|
|
79
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
80
|
+
};
|
|
81
|
+
// LOAD_IND_I8
|
|
82
|
+
export const load_ind_i8 = (r, args, registers, memory) => {
|
|
83
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.c)));
|
|
84
|
+
const result = memory.getI8(faultRes, address);
|
|
85
|
+
if (!faultRes.isFault) {
|
|
86
|
+
registers[Inst.reg(args.b)] = result;
|
|
87
|
+
}
|
|
88
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
89
|
+
};
|
|
90
|
+
// LOAD_IND_U16
|
|
91
|
+
export const load_ind_u16 = (r, args, registers, memory) => {
|
|
92
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.c)));
|
|
93
|
+
const result = memory.getU16(faultRes, address);
|
|
94
|
+
if (!faultRes.isFault) {
|
|
95
|
+
registers[Inst.reg(args.b)] = result;
|
|
96
|
+
}
|
|
97
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
98
|
+
};
|
|
99
|
+
// LOAD_IND_I16
|
|
100
|
+
export const load_ind_i16 = (r, args, registers, memory) => {
|
|
101
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.c)));
|
|
102
|
+
const result = memory.getI16(faultRes, address);
|
|
103
|
+
if (!faultRes.isFault) {
|
|
104
|
+
registers[Inst.reg(args.b)] = result;
|
|
105
|
+
}
|
|
106
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
107
|
+
};
|
|
108
|
+
// LOAD_IND_U32
|
|
109
|
+
export const load_ind_u32 = (r, args, registers, memory) => {
|
|
110
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.c)));
|
|
111
|
+
const result = memory.getU32(faultRes, address);
|
|
112
|
+
if (!faultRes.isFault) {
|
|
113
|
+
registers[Inst.reg(args.b)] = result;
|
|
114
|
+
}
|
|
115
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
116
|
+
};
|
|
117
|
+
// LOAD_IND_I32
|
|
118
|
+
export const load_ind_i32 = (r, args, registers, memory) => {
|
|
119
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.c)));
|
|
120
|
+
const result = memory.getI32(faultRes, address);
|
|
121
|
+
if (!faultRes.isFault) {
|
|
122
|
+
registers[Inst.reg(args.b)] = result;
|
|
123
|
+
}
|
|
124
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
125
|
+
};
|
|
126
|
+
// LOAD_IND_U64
|
|
127
|
+
export const load_ind_u64 = (r, args, registers, memory) => {
|
|
128
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.c)));
|
|
129
|
+
const result = memory.getU64(faultRes, u32(address));
|
|
130
|
+
if (!faultRes.isFault) {
|
|
131
|
+
registers[Inst.reg(args.b)] = result;
|
|
132
|
+
}
|
|
133
|
+
return OutcomeData.okOrFault(r, faultRes);
|
|
134
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InstructionRun } from "./outcome";
|
|
2
|
+
export declare const and_imm: InstructionRun;
|
|
3
|
+
export declare const xor_imm: InstructionRun;
|
|
4
|
+
export declare const or_imm: InstructionRun;
|
|
5
|
+
export declare const and: InstructionRun;
|
|
6
|
+
export declare const xor: InstructionRun;
|
|
7
|
+
export declare const or: InstructionRun;
|
|
8
|
+
export declare const and_inv: InstructionRun;
|
|
9
|
+
export declare const or_inv: InstructionRun;
|
|
10
|
+
export declare const xnor: InstructionRun;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { OutcomeData } from "./outcome";
|
|
2
|
+
import { Inst } from "./utils";
|
|
3
|
+
// AND_IMM
|
|
4
|
+
export const and_imm = (r, args, registers) => {
|
|
5
|
+
registers[Inst.reg(args.b)] = registers[Inst.reg(args.a)] & Inst.u32SignExtend(args.c);
|
|
6
|
+
return OutcomeData.ok(r);
|
|
7
|
+
};
|
|
8
|
+
// XOR_IMM
|
|
9
|
+
export const xor_imm = (r, args, registers) => {
|
|
10
|
+
registers[Inst.reg(args.b)] = registers[Inst.reg(args.a)] ^ Inst.u32SignExtend(args.c);
|
|
11
|
+
return OutcomeData.ok(r);
|
|
12
|
+
};
|
|
13
|
+
// OR_IMM
|
|
14
|
+
export const or_imm = (r, args, registers) => {
|
|
15
|
+
registers[Inst.reg(args.b)] = registers[Inst.reg(args.a)] | Inst.u32SignExtend(args.c);
|
|
16
|
+
return OutcomeData.ok(r);
|
|
17
|
+
};
|
|
18
|
+
// AND
|
|
19
|
+
export const and = (r, args, registers) => {
|
|
20
|
+
registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)] & registers[Inst.reg(args.a)];
|
|
21
|
+
return OutcomeData.ok(r);
|
|
22
|
+
};
|
|
23
|
+
// XOR
|
|
24
|
+
export const xor = (r, args, registers) => {
|
|
25
|
+
registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)] ^ registers[Inst.reg(args.a)];
|
|
26
|
+
return OutcomeData.ok(r);
|
|
27
|
+
};
|
|
28
|
+
// OR
|
|
29
|
+
export const or = (r, args, registers) => {
|
|
30
|
+
registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)] | registers[Inst.reg(args.a)];
|
|
31
|
+
return OutcomeData.ok(r);
|
|
32
|
+
};
|
|
33
|
+
// AND_INV
|
|
34
|
+
export const and_inv = (r, args, registers) => {
|
|
35
|
+
registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)] & ~registers[Inst.reg(args.a)];
|
|
36
|
+
return OutcomeData.ok(r);
|
|
37
|
+
};
|
|
38
|
+
// OR_INV
|
|
39
|
+
export const or_inv = (r, args, registers) => {
|
|
40
|
+
registers[Inst.reg(args.c)] = u64(registers[Inst.reg(args.b)] | ~registers[Inst.reg(args.a)]);
|
|
41
|
+
return OutcomeData.ok(r);
|
|
42
|
+
};
|
|
43
|
+
// XNOR
|
|
44
|
+
export const xnor = (r, args, registers) => {
|
|
45
|
+
registers[Inst.reg(args.c)] = u64(~(registers[Inst.reg(args.b)] ^ registers[Inst.reg(args.a)]));
|
|
46
|
+
return OutcomeData.ok(r);
|
|
47
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { InstructionRun } from "./outcome";
|
|
2
|
+
export declare const add_imm_32: InstructionRun;
|
|
3
|
+
export declare const mul_imm_32: InstructionRun;
|
|
4
|
+
export declare const neg_add_imm_32: InstructionRun;
|
|
5
|
+
export declare const add_imm: InstructionRun;
|
|
6
|
+
export declare const mul_imm: InstructionRun;
|
|
7
|
+
export declare const neg_add_imm: InstructionRun;
|
|
8
|
+
export declare const add_32: InstructionRun;
|
|
9
|
+
export declare const sub_32: InstructionRun;
|
|
10
|
+
export declare const mul_32: InstructionRun;
|
|
11
|
+
export declare const div_u_32: InstructionRun;
|
|
12
|
+
export declare const div_s_32: InstructionRun;
|
|
13
|
+
export declare const rem_u_32: InstructionRun;
|
|
14
|
+
export declare const rem_s_32: InstructionRun;
|
|
15
|
+
export declare const add_64: InstructionRun;
|
|
16
|
+
export declare const sub: InstructionRun;
|
|
17
|
+
export declare const mul: InstructionRun;
|
|
18
|
+
export declare const div_u: InstructionRun;
|
|
19
|
+
export declare const div_s: InstructionRun;
|
|
20
|
+
export declare const rem_u: InstructionRun;
|
|
21
|
+
export declare const rem_s: InstructionRun;
|
|
22
|
+
export declare const mul_upper_s_s: InstructionRun;
|
|
23
|
+
export declare const mul_upper_u_u: InstructionRun;
|
|
24
|
+
export declare const mul_upper_s_u: InstructionRun;
|
|
25
|
+
export declare const max: InstructionRun;
|
|
26
|
+
export declare const max_u: InstructionRun;
|
|
27
|
+
export declare const min: InstructionRun;
|
|
28
|
+
export declare const min_u: InstructionRun;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { portable } from "../portable";
|
|
2
|
+
import { OutcomeData } from "./outcome";
|
|
3
|
+
import { Inst, mulUpperSigned, mulUpperSignedUnsigned, mulUpperUnsigned } from "./utils";
|
|
4
|
+
// ADD_IMM_32
|
|
5
|
+
export const add_imm_32 = (r, args, registers) => {
|
|
6
|
+
const a = registers[Inst.reg(args.a)];
|
|
7
|
+
const c = Inst.u32SignExtend(args.c);
|
|
8
|
+
registers[Inst.reg(args.b)] = Inst.u32SignExtend(u32(portable.u64_add(a, c)));
|
|
9
|
+
return OutcomeData.ok(r);
|
|
10
|
+
};
|
|
11
|
+
// MUL_IMM_32
|
|
12
|
+
export const mul_imm_32 = (r, args, registers) => {
|
|
13
|
+
registers[Inst.reg(args.b)] = Inst.u32SignExtend(u32(portable.u64_mul(registers[Inst.reg(args.a)], u64(args.c))));
|
|
14
|
+
return OutcomeData.ok(r);
|
|
15
|
+
};
|
|
16
|
+
// NEG_ADD_IMM_32
|
|
17
|
+
export const neg_add_imm_32 = (r, args, registers) => {
|
|
18
|
+
const sum = portable.u64_sub(u64(args.c) | u64(4294967296), registers[Inst.reg(args.a)]);
|
|
19
|
+
registers[Inst.reg(args.b)] = Inst.u32SignExtend(u32(sum));
|
|
20
|
+
return OutcomeData.ok(r);
|
|
21
|
+
};
|
|
22
|
+
// ADD_IMM
|
|
23
|
+
export const add_imm = (r, args, registers) => {
|
|
24
|
+
const sum = portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.c));
|
|
25
|
+
registers[Inst.reg(args.b)] = sum;
|
|
26
|
+
return OutcomeData.ok(r);
|
|
27
|
+
};
|
|
28
|
+
// MUL_IMM
|
|
29
|
+
export const mul_imm = (r, args, registers) => {
|
|
30
|
+
registers[Inst.reg(args.b)] = portable.u64_mul(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.c));
|
|
31
|
+
return OutcomeData.ok(r);
|
|
32
|
+
};
|
|
33
|
+
// NEG_ADD_IMM
|
|
34
|
+
export const neg_add_imm = (r, args, registers) => {
|
|
35
|
+
const sum = portable.u64_sub(Inst.u32SignExtend(args.c), registers[Inst.reg(args.a)]);
|
|
36
|
+
registers[Inst.reg(args.b)] = sum;
|
|
37
|
+
return OutcomeData.ok(r);
|
|
38
|
+
};
|
|
39
|
+
// ADD_32
|
|
40
|
+
export const add_32 = (r, args, registers) => {
|
|
41
|
+
const a = u32(registers[Inst.reg(args.a)]);
|
|
42
|
+
const b = u32(registers[Inst.reg(args.b)]);
|
|
43
|
+
registers[Inst.reg(args.c)] = Inst.u32SignExtend(a + b);
|
|
44
|
+
return OutcomeData.ok(r);
|
|
45
|
+
};
|
|
46
|
+
// SUB_32
|
|
47
|
+
export const sub_32 = (r, args, registers) => {
|
|
48
|
+
const a = registers[Inst.reg(args.b)];
|
|
49
|
+
const b = u64(4294967296 - u32(registers[Inst.reg(args.a)]));
|
|
50
|
+
registers[Inst.reg(args.c)] = Inst.u32SignExtend(u32(portable.u64_add(a, b)));
|
|
51
|
+
return OutcomeData.ok(r);
|
|
52
|
+
};
|
|
53
|
+
// MUL_32
|
|
54
|
+
export const mul_32 = (r, args, registers) => {
|
|
55
|
+
registers[Inst.reg(args.c)] = Inst.u32SignExtend(u32(portable.u64_mul(registers[Inst.reg(args.a)], registers[Inst.reg(args.b)])));
|
|
56
|
+
return OutcomeData.ok(r);
|
|
57
|
+
};
|
|
58
|
+
// DIV_U_32
|
|
59
|
+
export const div_u_32 = (r, args, registers) => {
|
|
60
|
+
const a = u32(registers[Inst.reg(args.a)]);
|
|
61
|
+
if (a === 0) {
|
|
62
|
+
registers[Inst.reg(args.c)] = u64.MAX_VALUE;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const b = u32(registers[Inst.reg(args.b)]);
|
|
66
|
+
registers[Inst.reg(args.c)] = Inst.u32SignExtend(b / a);
|
|
67
|
+
}
|
|
68
|
+
return OutcomeData.ok(r);
|
|
69
|
+
};
|
|
70
|
+
// DIV_S_32
|
|
71
|
+
export const div_s_32 = (r, args, registers) => {
|
|
72
|
+
const b = i64(Inst.u32SignExtend(u32(registers[Inst.reg(args.b)])));
|
|
73
|
+
const a = i64(Inst.u32SignExtend(u32(registers[Inst.reg(args.a)])));
|
|
74
|
+
if (a === i64(0)) {
|
|
75
|
+
registers[Inst.reg(args.c)] = u64.MAX_VALUE;
|
|
76
|
+
}
|
|
77
|
+
else if (a === i64(-1) && b === i64(i32.MIN_VALUE)) {
|
|
78
|
+
registers[Inst.reg(args.c)] = u64(b);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
registers[Inst.reg(args.c)] = u64(b / a);
|
|
82
|
+
}
|
|
83
|
+
return OutcomeData.ok(r);
|
|
84
|
+
};
|
|
85
|
+
// REM_U_32
|
|
86
|
+
export const rem_u_32 = (r, args, registers) => {
|
|
87
|
+
const a = u32(registers[Inst.reg(args.a)]);
|
|
88
|
+
const b = u32(registers[Inst.reg(args.b)]);
|
|
89
|
+
if (a === 0) {
|
|
90
|
+
registers[Inst.reg(args.c)] = Inst.u32SignExtend(b);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
registers[Inst.reg(args.c)] = Inst.u32SignExtend(b % a);
|
|
94
|
+
}
|
|
95
|
+
return OutcomeData.ok(r);
|
|
96
|
+
};
|
|
97
|
+
// REM_S_32
|
|
98
|
+
export const rem_s_32 = (r, args, registers) => {
|
|
99
|
+
const b = i32(registers[Inst.reg(args.b)]);
|
|
100
|
+
const a = i32(registers[Inst.reg(args.a)]);
|
|
101
|
+
if (a === 0) {
|
|
102
|
+
registers[Inst.reg(args.c)] = u64(i64(b));
|
|
103
|
+
}
|
|
104
|
+
else if (a === -1 && b === i32.MIN_VALUE) {
|
|
105
|
+
registers[Inst.reg(args.c)] = u64(0);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
registers[Inst.reg(args.c)] = u64(i64(b) % i64(a));
|
|
109
|
+
}
|
|
110
|
+
return OutcomeData.ok(r);
|
|
111
|
+
};
|
|
112
|
+
// ADD_64
|
|
113
|
+
export const add_64 = (r, args, registers) => {
|
|
114
|
+
const a = registers[Inst.reg(args.a)];
|
|
115
|
+
const b = registers[Inst.reg(args.b)];
|
|
116
|
+
registers[Inst.reg(args.c)] = portable.u64_add(a, b);
|
|
117
|
+
return OutcomeData.ok(r);
|
|
118
|
+
};
|
|
119
|
+
// SUB
|
|
120
|
+
export const sub = (r, args, registers) => {
|
|
121
|
+
const a = registers[Inst.reg(args.a)];
|
|
122
|
+
const b = registers[Inst.reg(args.b)];
|
|
123
|
+
registers[Inst.reg(args.c)] = portable.u64_sub(b, a);
|
|
124
|
+
return OutcomeData.ok(r);
|
|
125
|
+
};
|
|
126
|
+
// MUL
|
|
127
|
+
export const mul = (r, args, registers) => {
|
|
128
|
+
const a = registers[Inst.reg(args.a)];
|
|
129
|
+
const b = registers[Inst.reg(args.b)];
|
|
130
|
+
registers[Inst.reg(args.c)] = portable.u64_mul(a, b);
|
|
131
|
+
return OutcomeData.ok(r);
|
|
132
|
+
};
|
|
133
|
+
// DIV_U
|
|
134
|
+
export const div_u = (r, args, registers) => {
|
|
135
|
+
if (registers[Inst.reg(args.a)] === u64(0)) {
|
|
136
|
+
registers[Inst.reg(args.c)] = u64.MAX_VALUE;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)] / registers[Inst.reg(args.a)];
|
|
140
|
+
}
|
|
141
|
+
return OutcomeData.ok(r);
|
|
142
|
+
};
|
|
143
|
+
// DIV_S
|
|
144
|
+
export const div_s = (r, args, registers) => {
|
|
145
|
+
const b = i64(registers[Inst.reg(args.b)]);
|
|
146
|
+
const a = i64(registers[Inst.reg(args.a)]);
|
|
147
|
+
if (a === i64(0)) {
|
|
148
|
+
registers[Inst.reg(args.c)] = u64.MAX_VALUE;
|
|
149
|
+
}
|
|
150
|
+
else if (a === i64(-1) && b === i64.MIN_VALUE) {
|
|
151
|
+
registers[Inst.reg(args.c)] = u64(b);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
registers[Inst.reg(args.c)] = u64(b / a);
|
|
155
|
+
}
|
|
156
|
+
return OutcomeData.ok(r);
|
|
157
|
+
};
|
|
158
|
+
// REM_U
|
|
159
|
+
export const rem_u = (r, args, registers) => {
|
|
160
|
+
if (registers[Inst.reg(args.a)] === u64(0)) {
|
|
161
|
+
registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)];
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)] % registers[Inst.reg(args.a)];
|
|
165
|
+
}
|
|
166
|
+
return OutcomeData.ok(r);
|
|
167
|
+
};
|
|
168
|
+
// REM_S
|
|
169
|
+
export const rem_s = (r, args, registers) => {
|
|
170
|
+
const b = i64(registers[Inst.reg(args.b)]);
|
|
171
|
+
const a = i64(registers[Inst.reg(args.a)]);
|
|
172
|
+
if (a === i64(0)) {
|
|
173
|
+
registers[Inst.reg(args.c)] = u64(b);
|
|
174
|
+
}
|
|
175
|
+
else if (a === i64(-1) && b === i64.MIN_VALUE) {
|
|
176
|
+
registers[Inst.reg(args.c)] = u64(0);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
registers[Inst.reg(args.c)] = u64(b % a);
|
|
180
|
+
}
|
|
181
|
+
return OutcomeData.ok(r);
|
|
182
|
+
};
|
|
183
|
+
// MUL_UPPER_S_S
|
|
184
|
+
export const mul_upper_s_s = (r, args, registers) => {
|
|
185
|
+
registers[Inst.reg(args.c)] = mulUpperSigned(i64(registers[Inst.reg(args.b)]), i64(registers[Inst.reg(args.a)]));
|
|
186
|
+
return OutcomeData.ok(r);
|
|
187
|
+
};
|
|
188
|
+
// MUL_UPPER_U_U
|
|
189
|
+
export const mul_upper_u_u = (r, args, registers) => {
|
|
190
|
+
registers[Inst.reg(args.c)] = mulUpperUnsigned(registers[Inst.reg(args.b)], registers[Inst.reg(args.a)]);
|
|
191
|
+
return OutcomeData.ok(r);
|
|
192
|
+
};
|
|
193
|
+
// MUL_UPPER_S_U
|
|
194
|
+
export const mul_upper_s_u = (r, args, registers) => {
|
|
195
|
+
registers[Inst.reg(args.c)] = mulUpperSignedUnsigned(i64(registers[Inst.reg(args.b)]), registers[Inst.reg(args.a)]);
|
|
196
|
+
return OutcomeData.ok(r);
|
|
197
|
+
};
|
|
198
|
+
// MAX
|
|
199
|
+
export const max = (r, args, registers) => {
|
|
200
|
+
const a = i64(registers[Inst.reg(args.a)]);
|
|
201
|
+
const b = i64(registers[Inst.reg(args.b)]);
|
|
202
|
+
registers[Inst.reg(args.c)] = u64(a < b ? b : a);
|
|
203
|
+
return OutcomeData.ok(r);
|
|
204
|
+
};
|
|
205
|
+
// MAX_U
|
|
206
|
+
export const max_u = (r, args, registers) => {
|
|
207
|
+
const a = registers[Inst.reg(args.a)];
|
|
208
|
+
const b = registers[Inst.reg(args.b)];
|
|
209
|
+
registers[Inst.reg(args.c)] = a < b ? b : a;
|
|
210
|
+
return OutcomeData.ok(r);
|
|
211
|
+
};
|
|
212
|
+
// MIN
|
|
213
|
+
export const min = (r, args, registers) => {
|
|
214
|
+
const a = i64(registers[Inst.reg(args.a)]);
|
|
215
|
+
const b = i64(registers[Inst.reg(args.b)]);
|
|
216
|
+
registers[Inst.reg(args.c)] = u64(a > b ? b : a);
|
|
217
|
+
return OutcomeData.ok(r);
|
|
218
|
+
};
|
|
219
|
+
// MIN_U
|
|
220
|
+
export const min_u = (r, args, registers) => {
|
|
221
|
+
const a = registers[Inst.reg(args.a)];
|
|
222
|
+
const b = registers[Inst.reg(args.b)];
|
|
223
|
+
registers[Inst.reg(args.c)] = a > b ? b : a;
|
|
224
|
+
return OutcomeData.ok(r);
|
|
225
|
+
};
|