Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GP 0.5.4] New instructions #32

Merged
merged 9 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
Expand All @@ -9,31 +6,41 @@ on:
pull_request:
branches: [ "main" ]

env:
NODE_VERSION: 22.x

jobs:
build:
jamtestvectors:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- run: npm ci
- run: npm run qa
- run: npm run build --if-present
- run: npm test --if-present

- run: npm run build
- name: Checkout JAM test vectors
uses: actions/checkout@v4
with:
repository: FluffyLabs/jamtestvectors
path: "./jamtestvectors"
ref: 0746da541814a6e1bb5da0ece4b1d249a10e5a13 # TODO Temporary 64-bit
ref: 747c2525145d2ed720c7168e3afa8582f66d00c2 # GP0.5.4
- run: npm start ./jamtestvectors/pvm/programs/*.json

build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- run: npm ci
- run: npm run qa
- run: npm run build
- run: npm test --if-present


3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Assembly Script implementation of the JAM PVM (32bit).

- [x] Memory
- [x] [JAM tests](https://github.com/w3f/jamtestvectors/pull/3) compatibility
- [ ] 64-bit & new instructions ([GrayPaper v0.5.0](https://graypaper.fluffylabs.dev))
- [x] 64-bit & new instructions ([GrayPaper v0.5.0](https://graypaper.fluffylabs.dev))
- [x] GP 0.5.4 compatibility (ZBB extensions)

### Why?

Expand Down
6 changes: 6 additions & 0 deletions asconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"shrinkLevel": 0,
"converge": false,
"noAssert": false
},
"test": {
"outFile": "build/test.wasm",
"textFile": "build/test.wat",
"sourceMap": true,
"debug": true
}
},
"options": {
Expand Down
57 changes: 35 additions & 22 deletions assembly/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,99 +21,112 @@ export const REQUIRED_BYTES = [<i32>0, 0, 1, 0, 1, 9, 1, 1, 1, 1, 1, 2, 2];

// @unmanaged
export class Args {
static from(a: u32, b: u32 = 0, c: u32 = 0, d: u32 = 0): Args {
const x = new Args();
x.a = a;
x.b = b;
x.c = c;
x.d = d;
return x;
}

/**
* TwoReg: `omega_A`
* TwoRegOneOff: `omega_B`
* ThreeReg: `omega_B`
*/
a: u32 = 0;
/**
* TwoReg: `omega'_D`
* TwoRegOneOff: `omega'_A`
* ThreeReg: `omega_A`
*/
b: u32 = 0;
/**
* ThreeReg: `omega'_D`
*/
c: u32 = 0;
d: u32 = 0;
}

function asArgs(a: u32, b: u32, c: u32, d: u32): Args {
const x = new Args();
x.a = a;
x.b = b;
x.c = c;
x.d = d;
return x;
}

type ArgsDecoder = (data: Uint8Array, immLimit: u32) => Args;

function twoImm(data: Uint8Array, lim: u32): Args {
const n = nibbles(data[0]);
const split = <i32>Math.min(4, n.low) + 1;
const first = decodeI32(data, 1, split);
const second = decodeI32(data, split, lim);
return asArgs(first, second, 0, 0);
return Args.from(first, second, 0, 0);
}

export const DECODERS: ArgsDecoder[] = [
// DECODERS[Arguments.Zero] =
(_d, _l) => {
return asArgs(0, 0, 0, 0);
return Args.from(0, 0, 0, 0);
},
// DECODERS[Arguments.OneImm] =
(data, lim) => {
return asArgs(decodeI32(data, 0, lim), 0, 0, 0);
return Args.from(decodeI32(data, 0, lim), 0, 0, 0);
},
// DECODERS[Arguments.TwoImm] =
(data, lim) => twoImm(data, lim),
// DECODERS[Arguments.OneOff] =
(data, lim) => {
return asArgs(decodeI32(data, 0, lim), 0, 0, 0);
return Args.from(decodeI32(data, 0, lim), 0, 0, 0);
},
// DECODERS[Arguments.OneRegOneImm] =
(data, lim) => {
return asArgs(nibbles(data[0]).low, decodeI32(data, 1, lim), 0, 0);
return Args.from(nibbles(data[0]).low, decodeI32(data, 1, lim), 0, 0);
},
// DECODERS[Arguments.OneRegOneExtImm] =
(data, _lim) => {
const a = nibbles(data[0]).low;
const b = decodeU32(data.subarray(1));
const c = decodeU32(data.subarray(5));
return asArgs(a, b, c, 0);
return Args.from(a, b, c, 0);
},
//DECODERS[Arguments.OneRegTwoImm] =
(data, lim) => {
const n = nibbles(data[0]);
const split = <i32>Math.min(4, n.hig) + 1;
const immA = decodeI32(data, 1, split);
const immB = decodeI32(data, split, lim);
return asArgs(n.low, immA, immB, 0);
return Args.from(n.low, immA, immB, 0);
},
// DECODERS[Arguments.OneRegOneImmOneOff] =
(data, lim) => {
const n = nibbles(data[0]);
const split = <i32>Math.min(4, n.hig) + 1;
const immA = decodeI32(data, 1, split);
const offs = decodeI32(data, split, lim);
return asArgs(n.low, immA, offs, 0);
return Args.from(n.low, immA, offs, 0);
},
// DECODERS[Arguments.TwoReg] =
(data, _lim) => {
const n = nibbles(data[0]);
return asArgs(n.hig, n.low, 0, 0);
return Args.from(n.hig, n.low, 0, 0);
},
// DECODERS[Arguments.TwoRegOneImm] =
(data, lim) => {
const n = nibbles(data[0]);
return asArgs(n.hig, n.low, decodeI32(data, 1, lim), 0);
return Args.from(n.hig, n.low, decodeI32(data, 1, lim), 0);
},
// DECODERS[Arguments.TwoRegOneOff] =
(data, lim) => {
const n = nibbles(data[0]);
return asArgs(n.hig, n.low, decodeI32(data, 1, lim), 0);
return Args.from(n.hig, n.low, decodeI32(data, 1, lim), 0);
},
// DECODERS[Arguments.TwoRegTwoImm] =
(data, lim) => {
const n = nibbles(data[0]);
const result = twoImm(data.subarray(1), lim > 1 ? lim - 1 : 0);
return asArgs(n.hig, n.low, result.a, result.b);
return Args.from(n.hig, n.low, result.a, result.b);
},
// DECODERS[Arguments.ThreeReg] =
(data, _lim) => {
const a = nibbles(data[0]);
const b = nibbles(data[1]);
return asArgs(a.hig, a.low, b.low, 0);
return Args.from(a.hig, a.low, b.low, 0);
},
];

Expand Down
Loading
Loading