@fluffylabs/anan-as 1.2.0 → 1.3.0-1ebcf8f

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 (110) hide show
  1. package/dist/bin/index.js +138 -5
  2. package/dist/bin/src/fuzz.js +2 -2
  3. package/dist/bin/src/test-json.js +2 -6
  4. package/dist/bin/src/trace-parse.js +1 -0
  5. package/dist/bin/src/trace-replay.js +14 -9
  6. package/dist/bin/src/tracer.js +16 -13
  7. package/dist/bin/src/utils.js +2 -2
  8. package/dist/build/compiler-inline.js +1 -1
  9. package/dist/build/compiler.d.ts +17 -13
  10. package/dist/build/compiler.js +13 -21
  11. package/dist/build/compiler.wasm +0 -0
  12. package/dist/build/debug-inline.js +1 -1
  13. package/dist/build/debug-raw-inline.js +1 -1
  14. package/dist/build/debug-raw.d.ts +50 -112
  15. package/dist/build/debug-raw.js +78 -139
  16. package/dist/build/debug-raw.wasm +0 -0
  17. package/dist/build/debug.d.ts +50 -112
  18. package/dist/build/debug.js +81 -147
  19. package/dist/build/debug.wasm +0 -0
  20. package/dist/build/js/assembly/api-debugger.d.ts +55 -0
  21. package/dist/build/js/assembly/api-debugger.js +245 -0
  22. package/dist/build/js/assembly/api-internal.d.ts +13 -0
  23. package/dist/build/js/assembly/api-internal.js +191 -0
  24. package/dist/build/js/assembly/api-types.d.ts +45 -0
  25. package/dist/build/js/assembly/api-types.js +52 -0
  26. package/dist/build/js/assembly/api-utils.d.ts +79 -0
  27. package/dist/build/js/assembly/api-utils.js +221 -0
  28. package/dist/build/js/assembly/arguments.d.ts +44 -0
  29. package/dist/build/js/assembly/arguments.js +164 -0
  30. package/dist/build/js/assembly/codec.d.ts +24 -0
  31. package/dist/build/js/assembly/codec.js +139 -0
  32. package/dist/build/js/assembly/gas.d.ts +11 -0
  33. package/dist/build/js/assembly/gas.js +33 -0
  34. package/dist/build/js/assembly/index-shared.d.ts +4 -0
  35. package/dist/build/js/assembly/index-shared.js +4 -0
  36. package/dist/build/js/assembly/instructions/bit.d.ts +11 -0
  37. package/dist/build/js/assembly/instructions/bit.js +53 -0
  38. package/dist/build/js/assembly/instructions/branch.d.ts +17 -0
  39. package/dist/build/js/assembly/instructions/branch.js +120 -0
  40. package/dist/build/js/assembly/instructions/jump.d.ts +5 -0
  41. package/dist/build/js/assembly/instructions/jump.js +21 -0
  42. package/dist/build/js/assembly/instructions/load.d.ts +17 -0
  43. package/dist/build/js/assembly/instructions/load.js +134 -0
  44. package/dist/build/js/assembly/instructions/logic.d.ts +10 -0
  45. package/dist/build/js/assembly/instructions/logic.js +47 -0
  46. package/dist/build/js/assembly/instructions/math.d.ts +28 -0
  47. package/dist/build/js/assembly/instructions/math.js +225 -0
  48. package/dist/build/js/assembly/instructions/misc.d.ts +6 -0
  49. package/dist/build/js/assembly/instructions/misc.js +22 -0
  50. package/dist/build/js/assembly/instructions/mov.d.ts +6 -0
  51. package/dist/build/js/assembly/instructions/mov.js +35 -0
  52. package/dist/build/js/assembly/instructions/outcome.d.ts +30 -0
  53. package/dist/build/js/assembly/instructions/outcome.js +88 -0
  54. package/dist/build/js/assembly/instructions/rot.d.ts +15 -0
  55. package/dist/build/js/assembly/instructions/rot.js +66 -0
  56. package/dist/build/js/assembly/instructions/set.d.ts +7 -0
  57. package/dist/build/js/assembly/instructions/set.js +36 -0
  58. package/dist/build/js/assembly/instructions/shift.d.ts +19 -0
  59. package/dist/build/js/assembly/instructions/shift.js +121 -0
  60. package/dist/build/js/assembly/instructions/store.d.ts +17 -0
  61. package/dist/build/js/assembly/instructions/store.js +101 -0
  62. package/dist/build/js/assembly/instructions/utils.d.ts +25 -0
  63. package/dist/build/js/assembly/instructions/utils.js +91 -0
  64. package/dist/build/js/assembly/instructions-exe.d.ts +2 -0
  65. package/dist/build/js/assembly/instructions-exe.js +245 -0
  66. package/dist/build/js/assembly/instructions.d.ts +10 -0
  67. package/dist/build/js/assembly/instructions.js +252 -0
  68. package/dist/build/js/assembly/interpreter.d.ts +28 -0
  69. package/dist/build/js/assembly/interpreter.js +221 -0
  70. package/dist/build/js/assembly/math.d.ts +6 -0
  71. package/dist/build/js/assembly/math.js +22 -0
  72. package/dist/build/js/assembly/memory-page.d.ts +36 -0
  73. package/dist/build/js/assembly/memory-page.js +74 -0
  74. package/dist/build/js/assembly/memory.d.ts +83 -0
  75. package/dist/build/js/assembly/memory.js +482 -0
  76. package/dist/build/js/assembly/portable.d.ts +24 -0
  77. package/dist/build/js/assembly/portable.js +363 -0
  78. package/dist/build/js/assembly/program-build.d.ts +2 -0
  79. package/dist/build/js/assembly/program-build.js +104 -0
  80. package/dist/build/js/assembly/program.d.ts +85 -0
  81. package/dist/build/js/assembly/program.js +340 -0
  82. package/dist/build/js/assembly/registers.d.ts +6 -0
  83. package/dist/build/js/assembly/registers.js +9 -0
  84. package/dist/build/js/assembly/spi.d.ts +92 -0
  85. package/dist/build/js/assembly/spi.js +152 -0
  86. package/dist/build/js/portable/bootstrap.d.ts +1 -0
  87. package/dist/build/js/portable/bootstrap.js +6 -0
  88. package/dist/build/js/portable/index.d.ts +4 -0
  89. package/dist/build/js/portable/index.js +6 -0
  90. package/dist/build/js/portable-bundle.js +4497 -0
  91. package/dist/build/release-inline.js +1 -1
  92. package/dist/build/release-mini-inline.js +1 -1
  93. package/dist/build/release-mini.d.ts +50 -112
  94. package/dist/build/release-mini.js +81 -147
  95. package/dist/build/release-mini.wasm +0 -0
  96. package/dist/build/release-stub-inline.js +1 -1
  97. package/dist/build/release-stub.d.ts +50 -112
  98. package/dist/build/release-stub.js +81 -147
  99. package/dist/build/release-stub.wasm +0 -0
  100. package/dist/build/release.d.ts +50 -112
  101. package/dist/build/release.js +81 -147
  102. package/dist/build/release.wasm +0 -0
  103. package/dist/build/test-inline.js +1 -1
  104. package/dist/build/test.wasm +0 -0
  105. package/dist/test/test-gas-cost.js +2 -3
  106. package/dist/test/test-trace-format.js +166 -0
  107. package/dist/test/test-w3f-common.js +125 -0
  108. package/dist/test/test-w3f-portable.js +5 -0
  109. package/dist/test/test-w3f.js +3 -120
  110. package/package.json +22 -11
@@ -0,0 +1,6 @@
1
+ import { InstructionRun } from "./outcome";
2
+ export declare const INVALID: InstructionRun;
3
+ export declare const trap: InstructionRun;
4
+ export declare const fallthrough: InstructionRun;
5
+ export declare const ecalli: InstructionRun;
6
+ export declare const sbrk: InstructionRun;
@@ -0,0 +1,22 @@
1
+ import { MaybePageFault } from "../memory";
2
+ import { OutcomeData } from "./outcome";
3
+ import { Inst } from "./utils";
4
+ const faultRes = new MaybePageFault();
5
+ // INVALID
6
+ export const INVALID = (r) => OutcomeData.panic(r);
7
+ // TRAP
8
+ export const trap = (r) => OutcomeData.panic(r);
9
+ // FALLTHROUGH
10
+ export const fallthrough = (r) => OutcomeData.ok(r);
11
+ // ECALLI
12
+ export const ecalli = (r, args) => OutcomeData.hostCall(r, args.a);
13
+ // SBRK
14
+ export const sbrk = (r, args, registers, memory) => {
15
+ const res = memory.sbrk(faultRes, u32(registers[Inst.reg(args.a)]));
16
+ // out of memory
17
+ if (faultRes.isFault) {
18
+ return OutcomeData.okOrFault(r, faultRes);
19
+ }
20
+ registers[Inst.reg(args.b)] = res;
21
+ return OutcomeData.ok(r);
22
+ };
@@ -0,0 +1,6 @@
1
+ import { InstructionRun } from "./outcome";
2
+ export declare const move_reg: InstructionRun;
3
+ export declare const cmov_iz_imm: InstructionRun;
4
+ export declare const cmov_nz_imm: InstructionRun;
5
+ export declare const cmov_iz: InstructionRun;
6
+ export declare const cmov_nz: InstructionRun;
@@ -0,0 +1,35 @@
1
+ import { OutcomeData } from "./outcome";
2
+ import { Inst } from "./utils";
3
+ // MOVE_REG
4
+ export const move_reg = (r, args, registers) => {
5
+ registers[Inst.reg(args.b)] = registers[Inst.reg(args.a)];
6
+ return OutcomeData.ok(r);
7
+ };
8
+ // CMOV_IZ_IMM
9
+ export const cmov_iz_imm = (r, args, registers) => {
10
+ if (registers[Inst.reg(args.a)] === u64(0)) {
11
+ registers[Inst.reg(args.b)] = Inst.u32SignExtend(args.c);
12
+ }
13
+ return OutcomeData.ok(r);
14
+ };
15
+ // CMOV_NZ_IMM
16
+ export const cmov_nz_imm = (r, args, registers) => {
17
+ if (registers[Inst.reg(args.a)] !== u64(0)) {
18
+ registers[Inst.reg(args.b)] = Inst.u32SignExtend(args.c);
19
+ }
20
+ return OutcomeData.ok(r);
21
+ };
22
+ // CMOV_IZ
23
+ export const cmov_iz = (r, args, registers) => {
24
+ if (registers[Inst.reg(args.a)] === u64(0)) {
25
+ registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)];
26
+ }
27
+ return OutcomeData.ok(r);
28
+ };
29
+ // CMOV_NZ
30
+ export const cmov_nz = (r, args, registers) => {
31
+ if (registers[Inst.reg(args.a)] !== u64(0)) {
32
+ registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)];
33
+ }
34
+ return OutcomeData.ok(r);
35
+ };
@@ -0,0 +1,30 @@
1
+ import { Args } from "../arguments";
2
+ import { MaybePageFault, Memory } from "../memory";
3
+ import { Registers } from "../registers";
4
+ export type InstructionRun = (o: OutcomeData, args: Args, registers: Registers, memory: Memory) => OutcomeData;
5
+ export declare enum Result {
6
+ PANIC = 0,
7
+ FAULT = 1,
8
+ FAULT_ACCESS = 2,
9
+ HOST = 3
10
+ }
11
+ export declare enum Outcome {
12
+ Ok = 0,
13
+ StaticJump = 1,
14
+ DynamicJump = 2,
15
+ Result = 3
16
+ }
17
+ export declare class OutcomeData {
18
+ outcome: Outcome;
19
+ staticJump: i32;
20
+ dJump: u32;
21
+ result: Result;
22
+ exitCode: u32;
23
+ static status(r: OutcomeData, result: Result): OutcomeData;
24
+ static staticJump(r: OutcomeData, offset: i32): OutcomeData;
25
+ static dJump(r: OutcomeData, address: u32): OutcomeData;
26
+ static ok(r: OutcomeData): OutcomeData;
27
+ static panic(r: OutcomeData): OutcomeData;
28
+ static hostCall(r: OutcomeData, id: u32): OutcomeData;
29
+ static okOrFault(r: OutcomeData, pageFault: MaybePageFault): OutcomeData;
30
+ }
@@ -0,0 +1,88 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ export var Result;
8
+ (function (Result) {
9
+ Result[Result["PANIC"] = 0] = "PANIC";
10
+ Result[Result["FAULT"] = 1] = "FAULT";
11
+ Result[Result["FAULT_ACCESS"] = 2] = "FAULT_ACCESS";
12
+ Result[Result["HOST"] = 3] = "HOST";
13
+ })(Result || (Result = {}));
14
+ export var Outcome;
15
+ (function (Outcome) {
16
+ Outcome[Outcome["Ok"] = 0] = "Ok";
17
+ Outcome[Outcome["StaticJump"] = 1] = "StaticJump";
18
+ Outcome[Outcome["DynamicJump"] = 2] = "DynamicJump";
19
+ Outcome[Outcome["Result"] = 3] = "Result";
20
+ })(Outcome || (Outcome = {}));
21
+ export class OutcomeData {
22
+ constructor() {
23
+ this.outcome = Outcome.Ok;
24
+ this.staticJump = 0;
25
+ this.dJump = 0;
26
+ this.result = Result.PANIC;
27
+ this.exitCode = 0;
28
+ }
29
+ static status(r, result) {
30
+ r.outcome = Outcome.Result;
31
+ r.result = result;
32
+ return r;
33
+ }
34
+ static staticJump(r, offset) {
35
+ r.outcome = Outcome.StaticJump;
36
+ r.staticJump = offset;
37
+ return r;
38
+ }
39
+ static dJump(r, address) {
40
+ r.outcome = Outcome.DynamicJump;
41
+ r.dJump = address;
42
+ return r;
43
+ }
44
+ static ok(r) {
45
+ // outcome is already pre-set to Ok by the interpreter loop
46
+ return r;
47
+ }
48
+ static panic(r) {
49
+ return OutcomeData.status(r, Result.PANIC);
50
+ }
51
+ static hostCall(r, id) {
52
+ r.outcome = Outcome.Result;
53
+ r.result = Result.HOST;
54
+ r.exitCode = id;
55
+ return r;
56
+ }
57
+ static okOrFault(r, pageFault) {
58
+ if (pageFault.isFault) {
59
+ r.outcome = Outcome.Result;
60
+ // not accessible memory does not result in `FAULT`, but rather goes straight to TRAP
61
+ // yet in gas calculations we still subtract 1, unlike TRAP, but like FAULT.
62
+ r.result = pageFault.isAccess ? Result.FAULT_ACCESS : Result.FAULT;
63
+ r.exitCode = pageFault.fault;
64
+ }
65
+ return r;
66
+ }
67
+ }
68
+ __decorate([
69
+ inline
70
+ ], OutcomeData, "status", null);
71
+ __decorate([
72
+ inline
73
+ ], OutcomeData, "staticJump", null);
74
+ __decorate([
75
+ inline
76
+ ], OutcomeData, "dJump", null);
77
+ __decorate([
78
+ inline
79
+ ], OutcomeData, "ok", null);
80
+ __decorate([
81
+ inline
82
+ ], OutcomeData, "panic", null);
83
+ __decorate([
84
+ inline
85
+ ], OutcomeData, "hostCall", null);
86
+ __decorate([
87
+ inline
88
+ ], OutcomeData, "okOrFault", null);
@@ -0,0 +1,15 @@
1
+ import { InstructionRun } from "./outcome";
2
+ export declare const rot_r_64_imm: InstructionRun;
3
+ export declare const rot_r_64_imm_alt: InstructionRun;
4
+ export declare const rot_r_32_imm: InstructionRun;
5
+ export declare const rot_r_32_imm_alt: InstructionRun;
6
+ export declare const rot_l_64: InstructionRun;
7
+ export declare const rot_l_32: InstructionRun;
8
+ export declare const rot_r_64: InstructionRun;
9
+ export declare const rot_r_32: InstructionRun;
10
+ export declare namespace math {
11
+ function rot_r(v: u64, shift: u64): u64;
12
+ function rot_r_32(v: u32, shift: u32): u32;
13
+ function rot_l(v: u64, shift: u64): u64;
14
+ function rot_l_32(v: u32, shift: u32): u32;
15
+ }
@@ -0,0 +1,66 @@
1
+ import { portable } from "../portable";
2
+ import { OutcomeData } from "./outcome";
3
+ import { Inst } from "./utils";
4
+ // ROT_R_64_IMM
5
+ export const rot_r_64_imm = (r, args, regs) => {
6
+ regs[Inst.reg(args.b)] = math.rot_r(regs[Inst.reg(args.a)], Inst.u32SignExtend(args.c));
7
+ return OutcomeData.ok(r);
8
+ };
9
+ // ROT_R_64_IMM_ALT
10
+ export const rot_r_64_imm_alt = (r, args, regs) => {
11
+ regs[Inst.reg(args.b)] = math.rot_r(Inst.u32SignExtend(args.c), regs[Inst.reg(args.a)]);
12
+ return OutcomeData.ok(r);
13
+ };
14
+ // ROT_R_32_IMM
15
+ export const rot_r_32_imm = (r, args, regs) => {
16
+ regs[Inst.reg(args.b)] = Inst.u32SignExtend(math.rot_r_32(u32(regs[Inst.reg(args.a)]), u32(args.c)));
17
+ return OutcomeData.ok(r);
18
+ };
19
+ // ROT_R_32_IMM_ALT
20
+ export const rot_r_32_imm_alt = (r, args, regs) => {
21
+ regs[Inst.reg(args.b)] = Inst.u32SignExtend(math.rot_r_32(u32(args.c), u32(regs[Inst.reg(args.a)])));
22
+ return OutcomeData.ok(r);
23
+ };
24
+ // ROT_L_64
25
+ export const rot_l_64 = (r, args, regs) => {
26
+ regs[Inst.reg(args.c)] = math.rot_l(regs[Inst.reg(args.b)], regs[Inst.reg(args.a)]);
27
+ return OutcomeData.ok(r);
28
+ };
29
+ // ROT_L_32
30
+ export const rot_l_32 = (r, args, regs) => {
31
+ regs[Inst.reg(args.c)] = Inst.u32SignExtend(math.rot_l_32(u32(regs[Inst.reg(args.b)]), u32(regs[Inst.reg(args.a)])));
32
+ return OutcomeData.ok(r);
33
+ };
34
+ // ROT_R_64
35
+ export const rot_r_64 = (r, args, regs) => {
36
+ regs[Inst.reg(args.c)] = math.rot_r(regs[Inst.reg(args.b)], regs[Inst.reg(args.a)]);
37
+ return OutcomeData.ok(r);
38
+ };
39
+ // ROT_R_32
40
+ export const rot_r_32 = (r, args, regs) => {
41
+ regs[Inst.reg(args.c)] = Inst.u32SignExtend(math.rot_r_32(u32(regs[Inst.reg(args.b)]), u32(regs[Inst.reg(args.a)])));
42
+ return OutcomeData.ok(r);
43
+ };
44
+ export var math;
45
+ (function (math) {
46
+ // @inline
47
+ function rot_r(v, shift) {
48
+ return portable.rotr_u64(v, shift);
49
+ }
50
+ math.rot_r = rot_r;
51
+ // @inline
52
+ function rot_r_32(v, shift) {
53
+ return portable.rotr_u32(v, shift);
54
+ }
55
+ math.rot_r_32 = rot_r_32;
56
+ // @inline
57
+ function rot_l(v, shift) {
58
+ return portable.rotl_u64(v, shift);
59
+ }
60
+ math.rot_l = rot_l;
61
+ // @inline
62
+ function rot_l_32(v, shift) {
63
+ return portable.rotl_u32(v, shift);
64
+ }
65
+ math.rot_l_32 = rot_l_32;
66
+ })(math || (math = {}));
@@ -0,0 +1,7 @@
1
+ import { InstructionRun } from "./outcome";
2
+ export declare const set_lt_u_imm: InstructionRun;
3
+ export declare const set_lt_s_imm: InstructionRun;
4
+ export declare const set_gt_u_imm: InstructionRun;
5
+ export declare const set_gt_s_imm: InstructionRun;
6
+ export declare const set_lt_u: InstructionRun;
7
+ export declare const set_lt_s: InstructionRun;
@@ -0,0 +1,36 @@
1
+ import { OutcomeData } from "./outcome";
2
+ import { Inst } from "./utils";
3
+ // SET_LT_U_IMM
4
+ export const set_lt_u_imm = (r, args, registers) => {
5
+ const cond = registers[Inst.reg(args.a)] < u64(Inst.u32SignExtend(args.c));
6
+ registers[Inst.reg(args.b)] = cond ? u64(1) : u64(0);
7
+ return OutcomeData.ok(r);
8
+ };
9
+ // SET_LT_S_IMM
10
+ export const set_lt_s_imm = (r, args, registers) => {
11
+ const cond = i64(registers[Inst.reg(args.a)]) < i64(Inst.u32SignExtend(args.c));
12
+ registers[Inst.reg(args.b)] = cond ? u64(1) : u64(0);
13
+ return OutcomeData.ok(r);
14
+ };
15
+ // SET_GT_U_IMM
16
+ export const set_gt_u_imm = (r, args, registers) => {
17
+ const cond = registers[Inst.reg(args.a)] > u64(Inst.u32SignExtend(args.c));
18
+ registers[Inst.reg(args.b)] = cond ? u64(1) : u64(0);
19
+ return OutcomeData.ok(r);
20
+ };
21
+ // SET_GT_S_IMM
22
+ export const set_gt_s_imm = (r, args, registers) => {
23
+ const cond = i64(registers[Inst.reg(args.a)]) > i64(Inst.u32SignExtend(args.c));
24
+ registers[Inst.reg(args.b)] = cond ? u64(1) : u64(0);
25
+ return OutcomeData.ok(r);
26
+ };
27
+ // SET_LT_U
28
+ export const set_lt_u = (r, args, registers) => {
29
+ registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)] < registers[Inst.reg(args.a)] ? u64(1) : u64(0);
30
+ return OutcomeData.ok(r);
31
+ };
32
+ // SET_LT_S
33
+ export const set_lt_s = (r, args, registers) => {
34
+ registers[Inst.reg(args.c)] = i64(registers[Inst.reg(args.b)]) < i64(registers[Inst.reg(args.a)]) ? u64(1) : u64(0);
35
+ return OutcomeData.ok(r);
36
+ };
@@ -0,0 +1,19 @@
1
+ import { InstructionRun } from "./outcome";
2
+ export declare const shlo_l_imm_32: InstructionRun;
3
+ export declare const shlo_r_imm_32: InstructionRun;
4
+ export declare const shar_r_imm_32: InstructionRun;
5
+ export declare const shlo_l_imm_alt_32: InstructionRun;
6
+ export declare const shlo_r_imm_alt_32: InstructionRun;
7
+ export declare const shar_r_imm_alt_32: InstructionRun;
8
+ export declare const shlo_l_imm: InstructionRun;
9
+ export declare const shlo_r_imm: InstructionRun;
10
+ export declare const shar_r_imm: InstructionRun;
11
+ export declare const shlo_l_imm_alt: InstructionRun;
12
+ export declare const shlo_r_imm_alt: InstructionRun;
13
+ export declare const shar_r_imm_alt: InstructionRun;
14
+ export declare const shlo_l_32: InstructionRun;
15
+ export declare const shlo_r_32: InstructionRun;
16
+ export declare const shar_r_32: InstructionRun;
17
+ export declare const shlo_l: InstructionRun;
18
+ export declare const shlo_r: InstructionRun;
19
+ export declare const shar_r: InstructionRun;
@@ -0,0 +1,121 @@
1
+ import { OutcomeData } from "./outcome";
2
+ import { Inst } from "./utils";
3
+ const MAX_SHIFT_64 = 64;
4
+ const MAX_SHIFT_32 = 32;
5
+ // SHLO_L_IMM_32
6
+ export const shlo_l_imm_32 = (r, args, registers) => {
7
+ const shift = u32(args.c % MAX_SHIFT_32);
8
+ const value = u32(registers[Inst.reg(args.a)]);
9
+ registers[Inst.reg(args.b)] = Inst.u32SignExtend(value << shift);
10
+ return OutcomeData.ok(r);
11
+ };
12
+ // SHLO_R_IMM_32
13
+ export const shlo_r_imm_32 = (r, args, registers) => {
14
+ const shift = u32(args.c % MAX_SHIFT_32);
15
+ const value = u32(registers[Inst.reg(args.a)]);
16
+ registers[Inst.reg(args.b)] = Inst.u32SignExtend(value >>> shift);
17
+ return OutcomeData.ok(r);
18
+ };
19
+ // SHAR_R_IMM_32
20
+ export const shar_r_imm_32 = (r, args, registers) => {
21
+ const shift = u32(args.c % MAX_SHIFT_32);
22
+ const value = Inst.u32SignExtend(u32(registers[Inst.reg(args.a)]));
23
+ registers[Inst.reg(args.b)] = u64(i64(value) >> i64(shift));
24
+ return OutcomeData.ok(r);
25
+ };
26
+ // SHLO_L_IMM_ALT_32
27
+ export const shlo_l_imm_alt_32 = (r, args, registers) => {
28
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_32));
29
+ registers[Inst.reg(args.b)] = Inst.u32SignExtend(args.c << shift);
30
+ return OutcomeData.ok(r);
31
+ };
32
+ // SHLO_R_IMM_ALT_32
33
+ export const shlo_r_imm_alt_32 = (r, args, registers) => {
34
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_32));
35
+ registers[Inst.reg(args.b)] = Inst.u32SignExtend(args.c >>> shift);
36
+ return OutcomeData.ok(r);
37
+ };
38
+ // SHAR_R_IMM_ALT_32
39
+ export const shar_r_imm_alt_32 = (r, args, registers) => {
40
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_32));
41
+ const imm = Inst.u32SignExtend(args.c);
42
+ registers[Inst.reg(args.b)] = Inst.u32SignExtend(u32(i64(imm) >> i64(shift)));
43
+ return OutcomeData.ok(r);
44
+ };
45
+ // SHLO_L_IMM
46
+ export const shlo_l_imm = (r, args, registers) => {
47
+ const shift = u32(args.c % MAX_SHIFT_64);
48
+ registers[Inst.reg(args.b)] = u64(registers[Inst.reg(args.a)] << u64(shift));
49
+ return OutcomeData.ok(r);
50
+ };
51
+ // SHLO_R_IMM
52
+ export const shlo_r_imm = (r, args, registers) => {
53
+ const shift = u32(args.c % MAX_SHIFT_64);
54
+ registers[Inst.reg(args.b)] = registers[Inst.reg(args.a)] >> u64(shift);
55
+ return OutcomeData.ok(r);
56
+ };
57
+ // SHAR_R_IMM
58
+ export const shar_r_imm = (r, args, registers) => {
59
+ const shift = u32(args.c % MAX_SHIFT_64);
60
+ const value = i64(registers[Inst.reg(args.a)]);
61
+ registers[Inst.reg(args.b)] = u64(value >> i64(shift));
62
+ return OutcomeData.ok(r);
63
+ };
64
+ // SHLO_L_IMM_ALT
65
+ export const shlo_l_imm_alt = (r, args, registers) => {
66
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_64));
67
+ registers[Inst.reg(args.b)] = u64(Inst.u32SignExtend(args.c) << i64(shift));
68
+ return OutcomeData.ok(r);
69
+ };
70
+ // SHLO_R_IMM_ALT
71
+ export const shlo_r_imm_alt = (r, args, registers) => {
72
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_64));
73
+ registers[Inst.reg(args.b)] = u64(Inst.u32SignExtend(args.c)) >> u64(shift);
74
+ return OutcomeData.ok(r);
75
+ };
76
+ // SHAR_R_IMM_ALT
77
+ export const shar_r_imm_alt = (r, args, registers) => {
78
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_64));
79
+ const value = Inst.u32SignExtend(args.c);
80
+ registers[Inst.reg(args.b)] = Inst.u32SignExtend(u32(value >> i64(shift)));
81
+ return OutcomeData.ok(r);
82
+ };
83
+ // SHLO_L_32
84
+ export const shlo_l_32 = (r, args, registers) => {
85
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_32));
86
+ const value = u32(registers[Inst.reg(args.b)]);
87
+ registers[Inst.reg(args.c)] = Inst.u32SignExtend(value << shift);
88
+ return OutcomeData.ok(r);
89
+ };
90
+ // SHLO_R_32
91
+ export const shlo_r_32 = (r, args, registers) => {
92
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_32));
93
+ const value = u32(registers[Inst.reg(args.b)]);
94
+ registers[Inst.reg(args.c)] = Inst.u32SignExtend(value >>> shift);
95
+ return OutcomeData.ok(r);
96
+ };
97
+ // SHAR_R_32
98
+ export const shar_r_32 = (r, args, registers) => {
99
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_32));
100
+ const regValue = Inst.u32SignExtend(u32(registers[Inst.reg(args.b)]));
101
+ registers[Inst.reg(args.c)] = Inst.u32SignExtend(u32(i64(regValue) >> i64(shift)));
102
+ return OutcomeData.ok(r);
103
+ };
104
+ // SHLO_L
105
+ export const shlo_l = (r, args, registers) => {
106
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_64));
107
+ registers[Inst.reg(args.c)] = u64(registers[Inst.reg(args.b)] << u64(shift));
108
+ return OutcomeData.ok(r);
109
+ };
110
+ // SHLO_R
111
+ export const shlo_r = (r, args, registers) => {
112
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_64));
113
+ registers[Inst.reg(args.c)] = registers[Inst.reg(args.b)] >> u64(shift);
114
+ return OutcomeData.ok(r);
115
+ };
116
+ // SHAR_R
117
+ export const shar_r = (r, args, registers) => {
118
+ const shift = u32(registers[Inst.reg(args.a)] % u64(MAX_SHIFT_64));
119
+ registers[Inst.reg(args.c)] = u64(i64(registers[Inst.reg(args.b)]) >> i64(shift));
120
+ return OutcomeData.ok(r);
121
+ };
@@ -0,0 +1,17 @@
1
+ import { InstructionRun } from "./outcome";
2
+ export declare const store_imm_u8: InstructionRun;
3
+ export declare const store_imm_u16: InstructionRun;
4
+ export declare const store_imm_u32: InstructionRun;
5
+ export declare const store_imm_u64: InstructionRun;
6
+ export declare const store_u8: InstructionRun;
7
+ export declare const store_u16: InstructionRun;
8
+ export declare const store_u32: InstructionRun;
9
+ export declare const store_u64: InstructionRun;
10
+ export declare const store_imm_ind_u8: InstructionRun;
11
+ export declare const store_imm_ind_u16: InstructionRun;
12
+ export declare const store_imm_ind_u32: InstructionRun;
13
+ export declare const store_imm_ind_u64: InstructionRun;
14
+ export declare const store_ind_u8: InstructionRun;
15
+ export declare const store_ind_u16: InstructionRun;
16
+ export declare const store_ind_u32: InstructionRun;
17
+ export declare const store_ind_u64: InstructionRun;
@@ -0,0 +1,101 @@
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
+ // Helper function to compute effective address from base register and signed 32-bit offset
7
+ function effectiveAddress(registers, baseReg, offset) {
8
+ return u32(portable.u64_add(registers[Inst.reg(u64(baseReg))], Inst.u32SignExtend(offset)));
9
+ }
10
+ // STORE_IMM_U8
11
+ export const store_imm_u8 = (r, args, _registers, memory) => {
12
+ const address = args.a;
13
+ memory.setU8(faultRes, address, (args.b & 0xff));
14
+ return OutcomeData.okOrFault(r, faultRes);
15
+ };
16
+ // STORE_IMM_U16
17
+ export const store_imm_u16 = (r, args, _registers, memory) => {
18
+ const address = args.a;
19
+ memory.setU16(faultRes, address, (args.b & 65535));
20
+ return OutcomeData.okOrFault(r, faultRes);
21
+ };
22
+ // STORE_IMM_U32
23
+ export const store_imm_u32 = (r, args, _registers, memory) => {
24
+ const address = args.a;
25
+ memory.setU32(faultRes, address, args.b);
26
+ return OutcomeData.okOrFault(r, faultRes);
27
+ };
28
+ // STORE_IMM_U64
29
+ export const store_imm_u64 = (r, args, _registers, memory) => {
30
+ const address = args.a;
31
+ memory.setU64(faultRes, address, Inst.u32SignExtend(args.b));
32
+ return OutcomeData.okOrFault(r, faultRes);
33
+ };
34
+ // STORE_U8
35
+ export const store_u8 = (r, args, registers, memory) => {
36
+ memory.setU8(faultRes, args.b, (registers[Inst.reg(args.a)] & u64(0xff)));
37
+ return OutcomeData.okOrFault(r, faultRes);
38
+ };
39
+ // STORE_U16
40
+ export const store_u16 = (r, args, registers, memory) => {
41
+ memory.setU16(faultRes, args.b, (registers[Inst.reg(args.a)] & u64(65535)));
42
+ return OutcomeData.okOrFault(r, faultRes);
43
+ };
44
+ // STORE_U32
45
+ export const store_u32 = (r, args, registers, memory) => {
46
+ memory.setU32(faultRes, args.b, u32(registers[Inst.reg(args.a)]));
47
+ return OutcomeData.okOrFault(r, faultRes);
48
+ };
49
+ // STORE_U64
50
+ export const store_u64 = (r, args, registers, memory) => {
51
+ memory.setU64(faultRes, args.b, registers[Inst.reg(args.a)]);
52
+ return OutcomeData.okOrFault(r, faultRes);
53
+ };
54
+ // STORE_IMM_IND_U8
55
+ export const store_imm_ind_u8 = (r, args, registers, memory) => {
56
+ const address = effectiveAddress(registers, args.a, args.b);
57
+ memory.setU8(faultRes, address, (args.c & 0xff));
58
+ return OutcomeData.okOrFault(r, faultRes);
59
+ };
60
+ // STORE_IMM_IND_U16
61
+ export const store_imm_ind_u16 = (r, args, registers, memory) => {
62
+ const address = effectiveAddress(registers, args.a, args.b);
63
+ memory.setU16(faultRes, address, (args.c & 65535));
64
+ return OutcomeData.okOrFault(r, faultRes);
65
+ };
66
+ // STORE_IMM_IND_U32
67
+ export const store_imm_ind_u32 = (r, args, registers, memory) => {
68
+ const address = effectiveAddress(registers, args.a, args.b);
69
+ memory.setU32(faultRes, address, args.c);
70
+ return OutcomeData.okOrFault(r, faultRes);
71
+ };
72
+ // STORE_IMM_IND_U64
73
+ export const store_imm_ind_u64 = (r, args, registers, memory) => {
74
+ const address = effectiveAddress(registers, args.a, args.b);
75
+ memory.setU64(faultRes, address, Inst.u32SignExtend(args.c));
76
+ return OutcomeData.okOrFault(r, faultRes);
77
+ };
78
+ // STORE_IND_U8
79
+ export const store_ind_u8 = (r, args, registers, memory) => {
80
+ const address = effectiveAddress(registers, args.a, args.c);
81
+ memory.setU8(faultRes, address, (registers[Inst.reg(args.b)] & u64(0xff)));
82
+ return OutcomeData.okOrFault(r, faultRes);
83
+ };
84
+ // STORE_IND_U16
85
+ export const store_ind_u16 = (r, args, registers, memory) => {
86
+ const address = effectiveAddress(registers, args.a, args.c);
87
+ memory.setU16(faultRes, address, (registers[Inst.reg(args.b)] & u64(65535)));
88
+ return OutcomeData.okOrFault(r, faultRes);
89
+ };
90
+ // STORE_IND_U32
91
+ export const store_ind_u32 = (r, args, registers, memory) => {
92
+ const address = effectiveAddress(registers, args.a, args.c);
93
+ memory.setU32(faultRes, address, u32(registers[Inst.reg(args.b)]));
94
+ return OutcomeData.okOrFault(r, faultRes);
95
+ };
96
+ // STORE_IND_U64
97
+ export const store_ind_u64 = (r, args, registers, memory) => {
98
+ const address = effectiveAddress(registers, args.a, args.c);
99
+ memory.setU64(faultRes, address, registers[Inst.reg(args.b)]);
100
+ return OutcomeData.okOrFault(r, faultRes);
101
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Multiply two unsigned 64-bit numbers and take the upper 64-bits of the result.
3
+ *
4
+ * The result of multiplication is a 128-bits number and we are only interested in the part that lands in the upper 64-bits.
5
+ * For example (for 32-bit case) if we multiply `0xffffffff * 0xffffffff`, we get:
6
+
7
+ * | 32-bits | 32-bits |
8
+ * +------------+------------+
9
+ * | upper | lower |
10
+ * | 0xfffffffe | 0x00000001 |
11
+ *
12
+ * So `0xfffffffe` is returned.
13
+ */
14
+ export declare function mulUpperUnsigned(a: u64, b: u64): u64;
15
+ /**
16
+ * Same as [mulUpperUnsigned] but treat the arguments as signed (two-complement) 64-bit numbers and the result alike.
17
+ */
18
+ export declare function mulUpperSigned(a: i64, b: i64): u64;
19
+ export declare function mulUpperSignedUnsigned(a: i64, b: u64): u64;
20
+ export declare class Inst {
21
+ static u8SignExtend(v: u8): i64;
22
+ static u16SignExtend(v: u16): i64;
23
+ static u32SignExtend(v: u32): i64;
24
+ static reg(v: u64): u32;
25
+ }