@fluffylabs/anan-as 1.2.0-ef04361 → 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.
- 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 +34 -32
- package/dist/build/debug-raw.js +62 -69
- package/dist/build/debug-raw.wasm +0 -0
- package/dist/build/debug.d.ts +34 -32
- package/dist/build/debug.js +63 -70
- package/dist/build/debug.wasm +0 -0
- package/dist/build/js/assembly/api-debugger.d.ts +4 -4
- package/dist/build/js/assembly/api-debugger.js +6 -6
- package/dist/build/js/assembly/api-internal.d.ts +1 -1
- package/dist/build/js/assembly/api-internal.js +2 -3
- package/dist/build/js/assembly/api-types.d.ts +4 -4
- package/dist/build/js/assembly/api-types.js +3 -4
- package/dist/build/js/assembly/api-utils.d.ts +14 -6
- package/dist/build/js/assembly/api-utils.js +28 -13
- package/dist/build/js/assembly/arguments.d.ts +4 -4
- package/dist/build/js/assembly/arguments.js +10 -10
- package/dist/build/js/assembly/gas.d.ts +8 -13
- package/dist/build/js/assembly/gas.js +17 -7
- package/dist/build/js/assembly/instructions/bit.js +22 -22
- package/dist/build/js/assembly/instructions/branch.js +56 -56
- package/dist/build/js/assembly/instructions/jump.js +10 -10
- package/dist/build/js/assembly/instructions/load.js +41 -41
- package/dist/build/js/assembly/instructions/logic.js +20 -20
- package/dist/build/js/assembly/instructions/math.js +105 -105
- package/dist/build/js/assembly/instructions/misc.js +10 -10
- package/dist/build/js/assembly/instructions/mov.js +16 -16
- package/dist/build/js/assembly/instructions/outcome.d.ts +7 -7
- package/dist/build/js/assembly/instructions/outcome.js +63 -38
- package/dist/build/js/assembly/instructions/rot.js +18 -18
- package/dist/build/js/assembly/instructions/set.js +18 -18
- package/dist/build/js/assembly/instructions/shift.js +59 -59
- package/dist/build/js/assembly/instructions/store.js +29 -29
- package/dist/build/js/assembly/instructions/utils.d.ts +6 -4
- package/dist/build/js/assembly/instructions/utils.js +32 -16
- package/dist/build/js/assembly/instructions.d.ts +2 -3
- package/dist/build/js/assembly/instructions.js +4 -4
- package/dist/build/js/assembly/interpreter.d.ts +0 -1
- package/dist/build/js/assembly/interpreter.js +30 -38
- package/dist/build/js/assembly/math.d.ts +6 -8
- package/dist/build/js/assembly/math.js +21 -13
- package/dist/build/js/assembly/memory-page.d.ts +2 -4
- package/dist/build/js/assembly/memory-page.js +13 -7
- package/dist/build/js/assembly/memory.d.ts +1 -0
- package/dist/build/js/assembly/memory.js +119 -23
- package/dist/build/js/assembly/portable.js +1 -0
- package/dist/build/js/assembly/program-build.js +4 -4
- package/dist/build/js/assembly/program.d.ts +15 -8
- package/dist/build/js/assembly/program.js +95 -39
- package/dist/build/js/assembly/spi.d.ts +1 -1
- package/dist/build/js/assembly/spi.js +2 -2
- package/dist/build/js/portable/bootstrap.js +1 -0
- package/dist/build/js/portable-bundle.js +829 -641
- package/dist/build/release-inline.js +1 -1
- package/dist/build/release-mini-inline.js +1 -1
- package/dist/build/release-mini.d.ts +34 -32
- package/dist/build/release-mini.js +63 -70
- package/dist/build/release-mini.wasm +0 -0
- package/dist/build/release-stub-inline.js +1 -1
- package/dist/build/release-stub.d.ts +34 -32
- package/dist/build/release-stub.js +63 -70
- package/dist/build/release-stub.wasm +0 -0
- package/dist/build/release.d.ts +34 -32
- package/dist/build/release.js +63 -70
- 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 +1 -2
- package/package.json +14 -10
- package/dist/build/js/assembly/gas-costs.d.ts +0 -6
- package/dist/build/js/assembly/gas-costs.js +0 -39
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { InitialChunk, InitialPage, VmOutput, VmPause } from "./api-types";
|
|
2
|
-
import {
|
|
2
|
+
import { Gas } from "./gas";
|
|
3
|
+
import { ProgramCounter } from "./program";
|
|
3
4
|
import { StandardProgram } from "./spi";
|
|
4
5
|
export declare enum InputKind {
|
|
5
6
|
Generic = 0,
|
|
@@ -9,7 +10,11 @@ export declare enum HasMetadata {
|
|
|
9
10
|
Yes = 0,
|
|
10
11
|
No = 1
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
declare class BlockGasCost {
|
|
14
|
+
pc: ProgramCounter;
|
|
15
|
+
gas: Gas;
|
|
16
|
+
}
|
|
17
|
+
export declare function getBlockGasCosts(input: u8[], kind: InputKind, withMetadata: HasMetadata): BlockGasCost[];
|
|
13
18
|
export declare function disassemble(input: u8[], kind: InputKind, withMetadata: HasMetadata): string;
|
|
14
19
|
export declare function prepareProgram(kind: InputKind, hasMetadata: HasMetadata, program: u8[],
|
|
15
20
|
/** NOTE: ignored in case of SPI. */
|
|
@@ -21,15 +26,17 @@ initialMemory: InitialChunk[],
|
|
|
21
26
|
/** NOTE: ONLY needed for SPI. */
|
|
22
27
|
args: u8[],
|
|
23
28
|
/** Preallocate a bunch of memory pages for faster execution. */
|
|
24
|
-
preallocateMemoryPages: u32
|
|
29
|
+
preallocateMemoryPages: u32,
|
|
30
|
+
/** Compute gas per-block instead of per-instruction. */
|
|
31
|
+
useBlockGas: boolean): StandardProgram;
|
|
25
32
|
/** Execute PVM program and stop. */
|
|
26
|
-
export declare function runProgram(program: StandardProgram, initialGas?: i64, programCounter?: u32, logs?: boolean,
|
|
33
|
+
export declare function runProgram(program: StandardProgram, initialGas?: i64, programCounter?: u32, logs?: boolean, dumpMemory?: boolean): VmOutput;
|
|
27
34
|
/**
|
|
28
35
|
* Allocate new PVM instance to execute given program.
|
|
29
36
|
*
|
|
30
37
|
* NOTE: the PVM MUST be de-allocated using `pvmDestroy`.
|
|
31
38
|
*/
|
|
32
|
-
export declare function pvmStart(program: StandardProgram
|
|
39
|
+
export declare function pvmStart(program: StandardProgram): u32;
|
|
33
40
|
/** Deallocate PVM resources. */
|
|
34
41
|
export declare function pvmDestroy(pvmId: u32): VmOutput | null;
|
|
35
42
|
/** Set register values of a paused PVM. */
|
|
@@ -68,4 +75,5 @@ export declare function pvmGetPagePointer(pvmId: u32, page: u32): usize;
|
|
|
68
75
|
/** Write a chunk of memory to given PVM instance. */
|
|
69
76
|
export declare function pvmWriteMemory(pvmId: u32, address: u32, data: Uint8Array): boolean;
|
|
70
77
|
/** Resume execution of paused VM. */
|
|
71
|
-
export declare function pvmResume(pvmId: u32, gas:
|
|
78
|
+
export declare function pvmResume(pvmId: u32, gas: Gas, pc: u32, logs?: boolean): VmPause | null;
|
|
79
|
+
export {};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { buildMemory, getAssembly, vmDestroy, vmExecute, vmInit, vmRunOnce } from "./api-internal";
|
|
2
2
|
import { VmInput, VmPause, VmRunOptions } from "./api-types";
|
|
3
|
-
import { computeGasCosts } from "./gas-costs";
|
|
4
3
|
import { MaybePageFault, MemoryBuilder } from "./memory";
|
|
5
|
-
import { portable } from "./portable";
|
|
6
4
|
import { deblob, extractCodeAndMetadata, liftBytes } from "./program";
|
|
7
5
|
import { NO_OF_REGISTERS, newRegisters } from "./registers";
|
|
8
6
|
import { decodeSpi, StandardProgram } from "./spi";
|
|
@@ -16,13 +14,29 @@ export var HasMetadata;
|
|
|
16
14
|
HasMetadata[HasMetadata["Yes"] = 0] = "Yes";
|
|
17
15
|
HasMetadata[HasMetadata["No"] = 1] = "No";
|
|
18
16
|
})(HasMetadata || (HasMetadata = {}));
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
class BlockGasCost {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.pc = 0;
|
|
20
|
+
this.gas = 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function getBlockGasCosts(input, kind, withMetadata) {
|
|
24
|
+
const program = prepareProgram(kind, withMetadata, input, [], [], [], [], 0, true);
|
|
25
|
+
const blockCosts = [];
|
|
26
|
+
const costs = program.program.gasCosts.codeAndGas;
|
|
27
|
+
for (let n = 0; n < costs.length; n += 1) {
|
|
28
|
+
const gas = costs[n] >> 8;
|
|
29
|
+
if (gas !== 0) {
|
|
30
|
+
const x = new BlockGasCost();
|
|
31
|
+
x.pc = n;
|
|
32
|
+
x.gas = costs[n];
|
|
33
|
+
blockCosts.push(x);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return blockCosts;
|
|
23
37
|
}
|
|
24
38
|
export function disassemble(input, kind, withMetadata) {
|
|
25
|
-
const program = prepareProgram(kind, withMetadata, input, [], [], [], [], 0);
|
|
39
|
+
const program = prepareProgram(kind, withMetadata, input, [], [], [], [], 0, false);
|
|
26
40
|
let output = "";
|
|
27
41
|
if (withMetadata === HasMetadata.Yes) {
|
|
28
42
|
output = "Metadata: \n";
|
|
@@ -43,7 +57,9 @@ initialMemory,
|
|
|
43
57
|
/** NOTE: ONLY needed for SPI. */
|
|
44
58
|
args,
|
|
45
59
|
/** Preallocate a bunch of memory pages for faster execution. */
|
|
46
|
-
preallocateMemoryPages
|
|
60
|
+
preallocateMemoryPages,
|
|
61
|
+
/** Compute gas per-block instead of per-instruction. */
|
|
62
|
+
useBlockGas) {
|
|
47
63
|
let code = liftBytes(program);
|
|
48
64
|
let metadata = new Uint8Array(0);
|
|
49
65
|
if (hasMetadata === HasMetadata.Yes) {
|
|
@@ -54,7 +70,7 @@ preallocateMemoryPages) {
|
|
|
54
70
|
metadata = data.metadata;
|
|
55
71
|
}
|
|
56
72
|
if (kind === InputKind.Generic) {
|
|
57
|
-
const program = deblob(code);
|
|
73
|
+
const program = deblob(code, useBlockGas);
|
|
58
74
|
const builder = new MemoryBuilder(preallocateMemoryPages);
|
|
59
75
|
const memory = buildMemory(builder, initialPageMap, initialMemory);
|
|
60
76
|
const registers = newRegisters();
|
|
@@ -74,13 +90,12 @@ preallocateMemoryPages) {
|
|
|
74
90
|
throw new Error(`Unknown kind: ${kind}`);
|
|
75
91
|
}
|
|
76
92
|
/** Execute PVM program and stop. */
|
|
77
|
-
export function runProgram(program, initialGas = 0, programCounter = 0, logs = false,
|
|
93
|
+
export function runProgram(program, initialGas = 0, programCounter = 0, logs = false, dumpMemory = false) {
|
|
78
94
|
const vmInput = new VmInput(program.program, program.memory, program.registers);
|
|
79
95
|
vmInput.gas = i64(initialGas);
|
|
80
96
|
vmInput.pc = programCounter;
|
|
81
97
|
const vmOptions = new VmRunOptions();
|
|
82
98
|
vmOptions.logs = logs;
|
|
83
|
-
vmOptions.useSbrkGas = useSbrkGas;
|
|
84
99
|
vmOptions.dumpMemory = dumpMemory;
|
|
85
100
|
return vmRunOnce(vmInput, vmOptions);
|
|
86
101
|
}
|
|
@@ -93,10 +108,10 @@ const pvms = new Map();
|
|
|
93
108
|
*
|
|
94
109
|
* NOTE: the PVM MUST be de-allocated using `pvmDestroy`.
|
|
95
110
|
*/
|
|
96
|
-
export function pvmStart(program
|
|
111
|
+
export function pvmStart(program) {
|
|
97
112
|
const vmInput = new VmInput(program.program, program.memory, program.registers);
|
|
98
113
|
nextPvmId += 1;
|
|
99
|
-
pvms.set(nextPvmId, vmInit(vmInput
|
|
114
|
+
pvms.set(nextPvmId, vmInit(vmInput));
|
|
100
115
|
return nextPvmId;
|
|
101
116
|
}
|
|
102
117
|
/** Deallocate PVM resources. */
|
|
@@ -14,9 +14,9 @@ export declare enum Arguments {
|
|
|
14
14
|
ThreeReg = 12
|
|
15
15
|
}
|
|
16
16
|
/** How many numbers in `Args` is relevant for given `Arguments`. */
|
|
17
|
-
export declare const RELEVANT_ARGS:
|
|
17
|
+
export declare const RELEVANT_ARGS: StaticArray<i32>;
|
|
18
18
|
/** How many bytes is required by given `Arguments`. */
|
|
19
|
-
export declare const REQUIRED_BYTES:
|
|
19
|
+
export declare const REQUIRED_BYTES: StaticArray<i32>;
|
|
20
20
|
export declare class Args {
|
|
21
21
|
fill(a: u32, b?: u32, c?: u32, d?: u32): Args;
|
|
22
22
|
/**
|
|
@@ -37,8 +37,8 @@ export declare class Args {
|
|
|
37
37
|
c: u32;
|
|
38
38
|
d: u32;
|
|
39
39
|
}
|
|
40
|
-
type ArgsDecoder = (args: Args, code: u8
|
|
41
|
-
export declare const DECODERS: ArgsDecoder
|
|
40
|
+
type ArgsDecoder = (args: Args, code: StaticArray<u8>, offset: u32, end: u32) => Args;
|
|
41
|
+
export declare const DECODERS: StaticArray<ArgsDecoder>;
|
|
42
42
|
export declare function lowNibble(byte: u8): u8;
|
|
43
43
|
export declare function higNibble(byte: u8): u8;
|
|
44
44
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IntMath } from "./math";
|
|
2
2
|
import { portable } from "./portable";
|
|
3
3
|
export var Arguments;
|
|
4
4
|
(function (Arguments) {
|
|
@@ -17,9 +17,9 @@ export var Arguments;
|
|
|
17
17
|
Arguments[Arguments["ThreeReg"] = 12] = "ThreeReg";
|
|
18
18
|
})(Arguments || (Arguments = {}));
|
|
19
19
|
/** How many numbers in `Args` is relevant for given `Arguments`. */
|
|
20
|
-
export const RELEVANT_ARGS = [0, 1, 2, 1, 2, 3, 3, 3, 2, 3, 3, 4, 3];
|
|
20
|
+
export const RELEVANT_ARGS = StaticArray.fromArray([0, 1, 2, 1, 2, 3, 3, 3, 2, 3, 3, 4, 3]);
|
|
21
21
|
/** How many bytes is required by given `Arguments`. */
|
|
22
|
-
export const REQUIRED_BYTES = [0, 0, 1, 0, 1, 9, 1, 1, 1, 1, 1, 2, 2];
|
|
22
|
+
export const REQUIRED_BYTES = StaticArray.fromArray([0, 0, 1, 0, 1, 9, 1, 1, 1, 1, 1, 2, 2]);
|
|
23
23
|
// @unmanaged
|
|
24
24
|
export class Args {
|
|
25
25
|
constructor() {
|
|
@@ -50,13 +50,13 @@ export class Args {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
function twoImm(args, code, offset, end) {
|
|
53
|
-
const low = lowNibble(portable.
|
|
54
|
-
const split = minI32(4, low) + 1;
|
|
53
|
+
const low = lowNibble(portable.staticArrayAt(code, offset));
|
|
54
|
+
const split = IntMath.minI32(4, low) + 1;
|
|
55
55
|
const first = decodeI32(code, offset + 1, offset + split);
|
|
56
56
|
const second = decodeI32(code, offset + split, end);
|
|
57
57
|
return args.fill(first, second, 0, 0);
|
|
58
58
|
}
|
|
59
|
-
export const DECODERS = [
|
|
59
|
+
export const DECODERS = StaticArray.fromArray([
|
|
60
60
|
// DECODERS[Arguments.Zero] =
|
|
61
61
|
(args, _d, _o, _l) => {
|
|
62
62
|
return args.fill(0, 0, 0, 0);
|
|
@@ -86,7 +86,7 @@ export const DECODERS = [
|
|
|
86
86
|
(args, data, o, lim) => {
|
|
87
87
|
const h = higNibble(data[o]);
|
|
88
88
|
const l = lowNibble(data[o]);
|
|
89
|
-
const split = minI32(4, h) + 1;
|
|
89
|
+
const split = IntMath.minI32(4, h) + 1;
|
|
90
90
|
const immA = decodeI32(data, o + 1, o + split);
|
|
91
91
|
const immB = decodeI32(data, o + split, lim);
|
|
92
92
|
return args.fill(l, immA, immB, 0);
|
|
@@ -95,7 +95,7 @@ export const DECODERS = [
|
|
|
95
95
|
(args, data, o, lim) => {
|
|
96
96
|
const h = higNibble(data[o]);
|
|
97
97
|
const l = lowNibble(data[o]);
|
|
98
|
-
const split = minI32(4, h) + 1;
|
|
98
|
+
const split = IntMath.minI32(4, h) + 1;
|
|
99
99
|
const immA = decodeI32(data, o + 1, o + split);
|
|
100
100
|
const offs = decodeI32(data, o + split, lim);
|
|
101
101
|
return args.fill(l, immA, offs, 0);
|
|
@@ -130,7 +130,7 @@ export const DECODERS = [
|
|
|
130
130
|
const b = lowNibble(data[o + 1]);
|
|
131
131
|
return args.fill(hig, low, b, 0);
|
|
132
132
|
},
|
|
133
|
-
];
|
|
133
|
+
]);
|
|
134
134
|
// @inline
|
|
135
135
|
export function lowNibble(byte) {
|
|
136
136
|
return byte & 0xf;
|
|
@@ -149,7 +149,7 @@ function decodeI32(input, start, end) {
|
|
|
149
149
|
for (let i = 0; i < len; i++) {
|
|
150
150
|
num |= u32(input[start + i]) << (i * 8);
|
|
151
151
|
}
|
|
152
|
-
const msb = portable.
|
|
152
|
+
const msb = portable.staticArrayAt(input, start + len - 1) & 0x80;
|
|
153
153
|
if (len < 4 && msb > 0) {
|
|
154
154
|
num |= 4294967295 << (len * 8);
|
|
155
155
|
}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
/** Gas type. */
|
|
2
|
-
export type Gas =
|
|
3
|
-
/** Create a new gas counter instance
|
|
4
|
-
export declare function gasCounter(gas:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
export interface GasCounter {
|
|
10
|
-
/** Return remaining gas. */
|
|
11
|
-
get(): Gas;
|
|
12
|
-
/** Overwite remaining gas. Prefer sub method instead. */
|
|
2
|
+
export type Gas = u64;
|
|
3
|
+
/** Create a new gas counter instance. */
|
|
4
|
+
export declare function gasCounter(gas: Gas): GasCounter;
|
|
5
|
+
export declare class GasCounter {
|
|
6
|
+
private gas;
|
|
7
|
+
constructor(gas: Gas);
|
|
13
8
|
set(g: Gas): void;
|
|
14
|
-
|
|
15
|
-
sub(g:
|
|
9
|
+
get(): Gas;
|
|
10
|
+
sub(g: u32): boolean;
|
|
16
11
|
}
|
|
@@ -1,23 +1,33 @@
|
|
|
1
|
-
|
|
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
|
+
/** Create a new gas counter instance. */
|
|
2
8
|
export function gasCounter(gas) {
|
|
3
|
-
return new
|
|
9
|
+
return new GasCounter(gas);
|
|
4
10
|
}
|
|
5
|
-
class
|
|
11
|
+
export class GasCounter {
|
|
6
12
|
constructor(gas) {
|
|
7
13
|
this.gas = gas;
|
|
8
14
|
}
|
|
9
15
|
set(g) {
|
|
10
|
-
this.gas =
|
|
16
|
+
this.gas = g;
|
|
11
17
|
}
|
|
12
18
|
get() {
|
|
13
19
|
return this.gas;
|
|
14
20
|
}
|
|
15
21
|
sub(g) {
|
|
16
|
-
|
|
17
|
-
if (this.gas
|
|
18
|
-
this.gas =
|
|
22
|
+
const cost = u64(g);
|
|
23
|
+
if (cost > this.gas) {
|
|
24
|
+
this.gas = u64(0);
|
|
19
25
|
return true;
|
|
20
26
|
}
|
|
27
|
+
this.gas = this.gas - cost;
|
|
21
28
|
return false;
|
|
22
29
|
}
|
|
23
30
|
}
|
|
31
|
+
__decorate([
|
|
32
|
+
inline
|
|
33
|
+
], GasCounter.prototype, "sub", null);
|
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
import { portable } from "../portable";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { OutcomeData } from "./outcome";
|
|
3
|
+
import { Inst } from "./utils";
|
|
4
4
|
// COUNT_SET_BITS_64
|
|
5
5
|
export const count_set_bits_64 = (r, args, regs) => {
|
|
6
|
-
regs[reg(args.b)] = portable.popcnt_u64(regs[reg(args.a)]);
|
|
7
|
-
return ok(r);
|
|
6
|
+
regs[Inst.reg(args.b)] = portable.popcnt_u64(regs[Inst.reg(args.a)]);
|
|
7
|
+
return OutcomeData.ok(r);
|
|
8
8
|
};
|
|
9
9
|
// COUNT_SET_BITS_32
|
|
10
10
|
export const count_set_bits_32 = (r, args, regs) => {
|
|
11
|
-
regs[reg(args.b)] = u64(portable.popcnt_u32(u32(regs[reg(args.a)])));
|
|
12
|
-
return ok(r);
|
|
11
|
+
regs[Inst.reg(args.b)] = u64(portable.popcnt_u32(u32(regs[Inst.reg(args.a)])));
|
|
12
|
+
return OutcomeData.ok(r);
|
|
13
13
|
};
|
|
14
14
|
// LEADING_ZERO_BITS_64
|
|
15
15
|
export const leading_zero_bits_64 = (r, args, regs) => {
|
|
16
|
-
regs[reg(args.b)] = portable.clz_u64(regs[reg(args.a)]);
|
|
17
|
-
return ok(r);
|
|
16
|
+
regs[Inst.reg(args.b)] = portable.clz_u64(regs[Inst.reg(args.a)]);
|
|
17
|
+
return OutcomeData.ok(r);
|
|
18
18
|
};
|
|
19
19
|
// LEADING_ZERO_BITS_32
|
|
20
20
|
export const leading_zero_bits_32 = (r, args, regs) => {
|
|
21
|
-
regs[reg(args.b)] = u64(portable.clz_u32(u32(regs[reg(args.a)])));
|
|
22
|
-
return ok(r);
|
|
21
|
+
regs[Inst.reg(args.b)] = u64(portable.clz_u32(u32(regs[Inst.reg(args.a)])));
|
|
22
|
+
return OutcomeData.ok(r);
|
|
23
23
|
};
|
|
24
24
|
// TRAILING_ZERO_BITS_64
|
|
25
25
|
export const trailing_zero_bits_64 = (r, args, regs) => {
|
|
26
|
-
regs[reg(args.b)] = portable.ctz_u64(regs[reg(args.a)]);
|
|
27
|
-
return ok(r);
|
|
26
|
+
regs[Inst.reg(args.b)] = portable.ctz_u64(regs[Inst.reg(args.a)]);
|
|
27
|
+
return OutcomeData.ok(r);
|
|
28
28
|
};
|
|
29
29
|
// TRAILING_ZERO_BITS_32
|
|
30
30
|
export const trailing_zero_bits_32 = (r, args, regs) => {
|
|
31
|
-
regs[reg(args.b)] = u64(portable.ctz_u32(u32(regs[reg(args.a)])));
|
|
32
|
-
return ok(r);
|
|
31
|
+
regs[Inst.reg(args.b)] = u64(portable.ctz_u32(u32(regs[Inst.reg(args.a)])));
|
|
32
|
+
return OutcomeData.ok(r);
|
|
33
33
|
};
|
|
34
34
|
// SIGN_EXTEND_8
|
|
35
35
|
export const sign_extend_8 = (r, args, regs) => {
|
|
36
|
-
regs[reg(args.b)] = u8SignExtend(u8(regs[reg(args.a)]));
|
|
37
|
-
return ok(r);
|
|
36
|
+
regs[Inst.reg(args.b)] = Inst.u8SignExtend(u8(regs[Inst.reg(args.a)]));
|
|
37
|
+
return OutcomeData.ok(r);
|
|
38
38
|
};
|
|
39
39
|
// SIGN_EXTEND_16
|
|
40
40
|
export const sign_extend_16 = (r, args, regs) => {
|
|
41
|
-
regs[reg(args.b)] = u16SignExtend(u16(regs[reg(args.a)]));
|
|
42
|
-
return ok(r);
|
|
41
|
+
regs[Inst.reg(args.b)] = Inst.u16SignExtend(u16(regs[Inst.reg(args.a)]));
|
|
42
|
+
return OutcomeData.ok(r);
|
|
43
43
|
};
|
|
44
44
|
// ZERO_EXTEND_16
|
|
45
45
|
export const zero_extend_16 = (r, args, regs) => {
|
|
46
|
-
regs[reg(args.b)] = u64(u16(regs[reg(args.a)]));
|
|
47
|
-
return ok(r);
|
|
46
|
+
regs[Inst.reg(args.b)] = u64(u16(regs[Inst.reg(args.a)]));
|
|
47
|
+
return OutcomeData.ok(r);
|
|
48
48
|
};
|
|
49
49
|
// REVERSE_BYTES
|
|
50
50
|
export const reverse_bytes = (r, args, regs) => {
|
|
51
|
-
regs[reg(args.b)] = portable.bswap_u64(regs[reg(args.a)]);
|
|
52
|
-
return ok(r);
|
|
51
|
+
regs[Inst.reg(args.b)] = portable.bswap_u64(regs[Inst.reg(args.a)]);
|
|
52
|
+
return OutcomeData.ok(r);
|
|
53
53
|
};
|
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { OutcomeData } from "./outcome";
|
|
2
|
+
import { Inst } from "./utils";
|
|
3
3
|
// BRANCH_EQ_IMM
|
|
4
4
|
export const branch_eq_imm = (r, args, registers) => {
|
|
5
|
-
const b = u64(u32SignExtend(args.b));
|
|
6
|
-
if (registers[reg(args.a)] === b) {
|
|
7
|
-
return staticJump(r, args.c);
|
|
5
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
6
|
+
if (registers[Inst.reg(args.a)] === b) {
|
|
7
|
+
return OutcomeData.staticJump(r, args.c);
|
|
8
8
|
}
|
|
9
|
-
return ok(r);
|
|
9
|
+
return OutcomeData.ok(r);
|
|
10
10
|
};
|
|
11
11
|
// BRANCH_NE_IMM
|
|
12
12
|
export const branch_ne_imm = (r, args, registers) => {
|
|
13
|
-
const b = u64(u32SignExtend(args.b));
|
|
14
|
-
if (registers[reg(args.a)] !== b) {
|
|
15
|
-
return staticJump(r, args.c);
|
|
13
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
14
|
+
if (registers[Inst.reg(args.a)] !== b) {
|
|
15
|
+
return OutcomeData.staticJump(r, args.c);
|
|
16
16
|
}
|
|
17
|
-
return ok(r);
|
|
17
|
+
return OutcomeData.ok(r);
|
|
18
18
|
};
|
|
19
19
|
// BRANCH_LT_U_IMM
|
|
20
20
|
export const branch_lt_u_imm = (r, args, registers) => {
|
|
21
|
-
const b = u64(u32SignExtend(args.b));
|
|
22
|
-
if (registers[reg(args.a)] < b) {
|
|
23
|
-
return staticJump(r, args.c);
|
|
21
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
22
|
+
if (registers[Inst.reg(args.a)] < b) {
|
|
23
|
+
return OutcomeData.staticJump(r, args.c);
|
|
24
24
|
}
|
|
25
|
-
return ok(r);
|
|
25
|
+
return OutcomeData.ok(r);
|
|
26
26
|
};
|
|
27
27
|
// BRANCH_LE_U_IMM
|
|
28
28
|
export const branch_le_u_imm = (r, args, registers) => {
|
|
29
|
-
const b = u64(u32SignExtend(args.b));
|
|
30
|
-
if (registers[reg(args.a)] <= b) {
|
|
31
|
-
return staticJump(r, args.c);
|
|
29
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
30
|
+
if (registers[Inst.reg(args.a)] <= b) {
|
|
31
|
+
return OutcomeData.staticJump(r, args.c);
|
|
32
32
|
}
|
|
33
|
-
return ok(r);
|
|
33
|
+
return OutcomeData.ok(r);
|
|
34
34
|
};
|
|
35
35
|
// BRANCH_GE_U_IMM
|
|
36
36
|
export const branch_ge_u_imm = (r, args, registers) => {
|
|
37
|
-
const b = u64(u32SignExtend(args.b));
|
|
38
|
-
if (registers[reg(args.a)] >= b) {
|
|
39
|
-
return staticJump(r, args.c);
|
|
37
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
38
|
+
if (registers[Inst.reg(args.a)] >= b) {
|
|
39
|
+
return OutcomeData.staticJump(r, args.c);
|
|
40
40
|
}
|
|
41
|
-
return ok(r);
|
|
41
|
+
return OutcomeData.ok(r);
|
|
42
42
|
};
|
|
43
43
|
// BRANCH_GT_U_IMM
|
|
44
44
|
export const branch_gt_u_imm = (r, args, registers) => {
|
|
45
|
-
const b = u64(u32SignExtend(args.b));
|
|
46
|
-
if (registers[reg(args.a)] > b) {
|
|
47
|
-
return staticJump(r, args.c);
|
|
45
|
+
const b = u64(Inst.u32SignExtend(args.b));
|
|
46
|
+
if (registers[Inst.reg(args.a)] > b) {
|
|
47
|
+
return OutcomeData.staticJump(r, args.c);
|
|
48
48
|
}
|
|
49
|
-
return ok(r);
|
|
49
|
+
return OutcomeData.ok(r);
|
|
50
50
|
};
|
|
51
51
|
// BRANCH_LT_S_IMM
|
|
52
52
|
export const branch_lt_s_imm = (r, args, registers) => {
|
|
53
|
-
if (i64(registers[reg(args.a)]) < i64(u32SignExtend(args.b))) {
|
|
54
|
-
return staticJump(r, args.c);
|
|
53
|
+
if (i64(registers[Inst.reg(args.a)]) < i64(Inst.u32SignExtend(args.b))) {
|
|
54
|
+
return OutcomeData.staticJump(r, args.c);
|
|
55
55
|
}
|
|
56
|
-
return ok(r);
|
|
56
|
+
return OutcomeData.ok(r);
|
|
57
57
|
};
|
|
58
58
|
// BRANCH_LE_S_IMM
|
|
59
59
|
export const branch_le_s_imm = (r, args, registers) => {
|
|
60
|
-
if (i64(registers[reg(args.a)]) <= i64(u32SignExtend(args.b))) {
|
|
61
|
-
return staticJump(r, args.c);
|
|
60
|
+
if (i64(registers[Inst.reg(args.a)]) <= i64(Inst.u32SignExtend(args.b))) {
|
|
61
|
+
return OutcomeData.staticJump(r, args.c);
|
|
62
62
|
}
|
|
63
|
-
return ok(r);
|
|
63
|
+
return OutcomeData.ok(r);
|
|
64
64
|
};
|
|
65
65
|
// BRANCH_GE_S_IMM
|
|
66
66
|
export const branch_ge_s_imm = (r, args, registers) => {
|
|
67
|
-
if (i64(registers[reg(args.a)]) >= i64(u32SignExtend(args.b))) {
|
|
68
|
-
return staticJump(r, args.c);
|
|
67
|
+
if (i64(registers[Inst.reg(args.a)]) >= i64(Inst.u32SignExtend(args.b))) {
|
|
68
|
+
return OutcomeData.staticJump(r, args.c);
|
|
69
69
|
}
|
|
70
|
-
return ok(r);
|
|
70
|
+
return OutcomeData.ok(r);
|
|
71
71
|
};
|
|
72
72
|
// BRANCH_GT_S_IMM
|
|
73
73
|
export const branch_gt_s_imm = (r, args, registers) => {
|
|
74
|
-
if (i64(registers[reg(args.a)]) > i64(u32SignExtend(args.b))) {
|
|
75
|
-
return staticJump(r, args.c);
|
|
74
|
+
if (i64(registers[Inst.reg(args.a)]) > i64(Inst.u32SignExtend(args.b))) {
|
|
75
|
+
return OutcomeData.staticJump(r, args.c);
|
|
76
76
|
}
|
|
77
|
-
return ok(r);
|
|
77
|
+
return OutcomeData.ok(r);
|
|
78
78
|
};
|
|
79
79
|
// BRANCH_EQ
|
|
80
80
|
export const branch_eq = (r, args, registers) => {
|
|
81
|
-
if (registers[reg(args.a)] === registers[reg(args.b)]) {
|
|
82
|
-
return staticJump(r, args.c);
|
|
81
|
+
if (registers[Inst.reg(args.a)] === registers[Inst.reg(args.b)]) {
|
|
82
|
+
return OutcomeData.staticJump(r, args.c);
|
|
83
83
|
}
|
|
84
|
-
return ok(r);
|
|
84
|
+
return OutcomeData.ok(r);
|
|
85
85
|
};
|
|
86
86
|
// BRANCH_NE
|
|
87
87
|
export const branch_ne = (r, args, registers) => {
|
|
88
|
-
if (registers[reg(args.a)] !== registers[reg(args.b)]) {
|
|
89
|
-
return staticJump(r, args.c);
|
|
88
|
+
if (registers[Inst.reg(args.a)] !== registers[Inst.reg(args.b)]) {
|
|
89
|
+
return OutcomeData.staticJump(r, args.c);
|
|
90
90
|
}
|
|
91
|
-
return ok(r);
|
|
91
|
+
return OutcomeData.ok(r);
|
|
92
92
|
};
|
|
93
93
|
// BRANCH_LT_U
|
|
94
94
|
export const branch_lt_u = (r, args, registers) => {
|
|
95
|
-
if (registers[reg(args.b)] < registers[reg(args.a)]) {
|
|
96
|
-
return staticJump(r, args.c);
|
|
95
|
+
if (registers[Inst.reg(args.b)] < registers[Inst.reg(args.a)]) {
|
|
96
|
+
return OutcomeData.staticJump(r, args.c);
|
|
97
97
|
}
|
|
98
|
-
return ok(r);
|
|
98
|
+
return OutcomeData.ok(r);
|
|
99
99
|
};
|
|
100
100
|
// BRANCH_LT_S
|
|
101
101
|
export const branch_lt_s = (r, args, registers) => {
|
|
102
|
-
if (i64(registers[reg(args.b)]) < i64(registers[reg(args.a)])) {
|
|
103
|
-
return staticJump(r, args.c);
|
|
102
|
+
if (i64(registers[Inst.reg(args.b)]) < i64(registers[Inst.reg(args.a)])) {
|
|
103
|
+
return OutcomeData.staticJump(r, args.c);
|
|
104
104
|
}
|
|
105
|
-
return ok(r);
|
|
105
|
+
return OutcomeData.ok(r);
|
|
106
106
|
};
|
|
107
107
|
// BRANCH_GE_U
|
|
108
108
|
export const branch_ge_u = (r, args, registers) => {
|
|
109
|
-
if (registers[reg(args.b)] >= registers[reg(args.a)]) {
|
|
110
|
-
return staticJump(r, args.c);
|
|
109
|
+
if (registers[Inst.reg(args.b)] >= registers[Inst.reg(args.a)]) {
|
|
110
|
+
return OutcomeData.staticJump(r, args.c);
|
|
111
111
|
}
|
|
112
|
-
return ok(r);
|
|
112
|
+
return OutcomeData.ok(r);
|
|
113
113
|
};
|
|
114
114
|
// BRANCH_GE_S
|
|
115
115
|
export const branch_ge_s = (r, args, registers) => {
|
|
116
|
-
if (i64(registers[reg(args.b)]) >= i64(registers[reg(args.a)])) {
|
|
117
|
-
return staticJump(r, args.c);
|
|
116
|
+
if (i64(registers[Inst.reg(args.b)]) >= i64(registers[Inst.reg(args.a)])) {
|
|
117
|
+
return OutcomeData.staticJump(r, args.c);
|
|
118
118
|
}
|
|
119
|
-
return ok(r);
|
|
119
|
+
return OutcomeData.ok(r);
|
|
120
120
|
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { portable } from "../portable";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { OutcomeData } from "./outcome";
|
|
3
|
+
import { Inst } from "./utils";
|
|
4
4
|
// JUMP
|
|
5
|
-
export const jump = (r, args) => staticJump(r, args.a);
|
|
5
|
+
export const jump = (r, args) => OutcomeData.staticJump(r, args.a);
|
|
6
6
|
// JUMP_IND
|
|
7
7
|
export const jump_ind = (r, args, registers) => {
|
|
8
|
-
const address = u32(portable.u64_add(registers[reg(args.a)], u32SignExtend(args.b)));
|
|
9
|
-
return dJump(r, address);
|
|
8
|
+
const address = u32(portable.u64_add(registers[Inst.reg(args.a)], Inst.u32SignExtend(args.b)));
|
|
9
|
+
return OutcomeData.dJump(r, address);
|
|
10
10
|
};
|
|
11
11
|
// LOAD_IMM_JUMP
|
|
12
12
|
export const load_imm_jump = (r, args, registers) => {
|
|
13
|
-
registers[reg(args.a)] = u32SignExtend(args.b);
|
|
14
|
-
return staticJump(r, args.c);
|
|
13
|
+
registers[Inst.reg(args.a)] = Inst.u32SignExtend(args.b);
|
|
14
|
+
return OutcomeData.staticJump(r, args.c);
|
|
15
15
|
};
|
|
16
16
|
// LOAD_IMM_JUMP_IND
|
|
17
17
|
export const load_imm_jump_ind = (r, args, registers) => {
|
|
18
|
-
const address = u32(portable.u64_add(registers[reg(args.a)], u32SignExtend(args.d)));
|
|
19
|
-
registers[reg(args.b)] = u32SignExtend(args.c);
|
|
20
|
-
return dJump(r, address);
|
|
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
21
|
};
|