Skip to content
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
8 changes: 4 additions & 4 deletions assembly/arguments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { minI32 } from "./math";
import { IntMath } from "./math";
import { portable } from "./portable";

export enum Arguments {
Expand Down Expand Up @@ -55,7 +55,7 @@ type ArgsDecoder = (args: Args, code: StaticArray<u8>, offset: u32, end: u32) =>

function twoImm(args: Args, code: StaticArray<u8>, offset: u32, end: u32): Args {
const low = lowNibble(portable.staticArrayAt(code, offset));
const split = minI32(4, low) + 1;
const split = IntMath.minI32(4, low) + 1;
const first = decodeI32(code, offset + 1, offset + split);
const second = decodeI32(code, offset + split, end);
return args.fill(first, second, 0, 0);
Expand Down Expand Up @@ -91,7 +91,7 @@ export const DECODERS: StaticArray<ArgsDecoder> = StaticArray.fromArray<ArgsDeco
(args, data, o, lim) => {
const h = higNibble(data[o]);
const l = lowNibble(data[o]);
const split = minI32(4, h) + 1;
const split = IntMath.minI32(4, h) + 1;
const immA = decodeI32(data, o + 1, o + split);
const immB = decodeI32(data, o + split, lim);
return args.fill(l, immA, immB, 0);
Expand All @@ -100,7 +100,7 @@ export const DECODERS: StaticArray<ArgsDecoder> = StaticArray.fromArray<ArgsDeco
(args, data, o, lim) => {
const h = higNibble(data[o]);
const l = lowNibble(data[o]);
const split = minI32(4, h) + 1;
const split = IntMath.minI32(4, h) + 1;
const immA = decodeI32(data, o + 1, o + split);
const offs = decodeI32(data, o + split, lim);
return args.fill(l, immA, offs, 0);
Expand Down
42 changes: 21 additions & 21 deletions assembly/instructions/bit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
zero_extend_16,
} from "./bit";
import { Outcome, OutcomeData } from "./outcome";
import { reg } from "./utils";
import { Inst } from "./utils";

export const TESTS: Test[] = [
test("count_set_bits_64", () => {
Expand All @@ -25,7 +25,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xffff_0000_1111;
regs[Inst.reg(args.a)] = 0xffff_0000_1111;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -34,7 +34,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 2 * 8 + 4);
assert.isEqual(regs[Inst.reg(0xf)], 2 * 8 + 4);
return assert;
}),
test("count_set_bits_32", () => {
Expand All @@ -44,7 +44,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xffff_0000_1111;
regs[Inst.reg(args.a)] = 0xffff_0000_1111;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -53,7 +53,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 4);
assert.isEqual(regs[Inst.reg(0xf)], 4);
return assert;
}),
test("leading_zero_bits_64", () => {
Expand All @@ -63,7 +63,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xfff0_0000_0111;
regs[Inst.reg(args.a)] = 0xfff0_0000_0111;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -72,7 +72,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 16);
assert.isEqual(regs[Inst.reg(0xf)], 16);
return assert;
}),
test("leading_zero_bits_32", () => {
Expand All @@ -82,7 +82,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xffff_0000_1111;
regs[Inst.reg(args.a)] = 0xffff_0000_1111;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -91,7 +91,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 19);
assert.isEqual(regs[Inst.reg(0xf)], 19);
return assert;
}),
test("trailing_zero_bits_64", () => {
Expand All @@ -101,7 +101,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xfff0_0000_0000;
regs[Inst.reg(args.a)] = 0xfff0_0000_0000;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -110,7 +110,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 36);
assert.isEqual(regs[Inst.reg(0xf)], 36);
return assert;
}),
test("trailing_zero_bits_32", () => {
Expand All @@ -120,7 +120,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xfff0_0000_0000;
regs[Inst.reg(args.a)] = 0xfff0_0000_0000;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -129,7 +129,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 32);
assert.isEqual(regs[Inst.reg(0xf)], 32);
return assert;
}),
test("sign_extend_8", () => {
Expand All @@ -139,7 +139,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xdead_beef;
regs[Inst.reg(args.a)] = 0xdead_beef;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -148,7 +148,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 0xffff_ffff_ffff_ffef);
assert.isEqual(regs[Inst.reg(0xf)], 0xffff_ffff_ffff_ffef);
return assert;
}),
test("sign_extend_16", () => {
Expand All @@ -158,7 +158,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xdead_beef;
regs[Inst.reg(args.a)] = 0xdead_beef;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -167,7 +167,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 0xffff_ffff_ffff_beef);
assert.isEqual(regs[Inst.reg(0xf)], 0xffff_ffff_ffff_beef);
return assert;
}),
test("zero_extend_16", () => {
Expand All @@ -177,7 +177,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xdead_beef;
regs[Inst.reg(args.a)] = 0xdead_beef;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -186,7 +186,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 0x0000_beef);
assert.isEqual(regs[Inst.reg(0xf)], 0x0000_beef);
return assert;
}),
test("reverse_bytes", () => {
Expand All @@ -196,7 +196,7 @@ export const TESTS: Test[] = [
args.a = 0x1;
args.b = 0xf;
const regs = newRegisters();
regs[reg(args.a)] = 0xfff0_dead_beef;
regs[Inst.reg(args.a)] = 0xfff0_dead_beef;
const memo = new MemoryBuilder().build();

// when
Expand All @@ -205,7 +205,7 @@ export const TESTS: Test[] = [
// then
const assert = new Assert();
assert.isEqual(res.outcome, Outcome.Ok, "outcome");
assert.isEqual(regs[reg(0xf)], 0xefbe_adde_f0ff_0000);
assert.isEqual(regs[Inst.reg(0xf)], 0xefbe_adde_f0ff_0000);
return assert;
}),
];
44 changes: 22 additions & 22 deletions assembly/instructions/bit.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
import { portable } from "../portable";
import { InstructionRun, ok } from "./outcome";
import { reg, u8SignExtend, u16SignExtend } from "./utils";
import { InstructionRun, OutcomeData } from "./outcome";
import { Inst } from "./utils";

// COUNT_SET_BITS_64
export const count_set_bits_64: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = portable.popcnt_u64(regs[reg(args.a)]);
return ok(r);
regs[Inst.reg(args.b)] = portable.popcnt_u64(regs[Inst.reg(args.a)]);
return OutcomeData.ok(r);
};

// COUNT_SET_BITS_32
export const count_set_bits_32: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = u64(portable.popcnt_u32(u32(regs[reg(args.a)])));
return ok(r);
regs[Inst.reg(args.b)] = u64(portable.popcnt_u32(u32(regs[Inst.reg(args.a)])));
return OutcomeData.ok(r);
};

// LEADING_ZERO_BITS_64
export const leading_zero_bits_64: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = portable.clz_u64(regs[reg(args.a)]);
return ok(r);
regs[Inst.reg(args.b)] = portable.clz_u64(regs[Inst.reg(args.a)]);
return OutcomeData.ok(r);
};

// LEADING_ZERO_BITS_32
export const leading_zero_bits_32: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = u64(portable.clz_u32(u32(regs[reg(args.a)])));
return ok(r);
regs[Inst.reg(args.b)] = u64(portable.clz_u32(u32(regs[Inst.reg(args.a)])));
return OutcomeData.ok(r);
};

// TRAILING_ZERO_BITS_64
export const trailing_zero_bits_64: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = portable.ctz_u64(regs[reg(args.a)]);
return ok(r);
regs[Inst.reg(args.b)] = portable.ctz_u64(regs[Inst.reg(args.a)]);
return OutcomeData.ok(r);
};

// TRAILING_ZERO_BITS_32
export const trailing_zero_bits_32: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = u64(portable.ctz_u32(u32(regs[reg(args.a)])));
return ok(r);
regs[Inst.reg(args.b)] = u64(portable.ctz_u32(u32(regs[Inst.reg(args.a)])));
return OutcomeData.ok(r);
};

// SIGN_EXTEND_8
export const sign_extend_8: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = u8SignExtend(u8(regs[reg(args.a)]));
return ok(r);
regs[Inst.reg(args.b)] = Inst.u8SignExtend(u8(regs[Inst.reg(args.a)]));
return OutcomeData.ok(r);
};

// SIGN_EXTEND_16
export const sign_extend_16: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = u16SignExtend(u16(regs[reg(args.a)]));
return ok(r);
regs[Inst.reg(args.b)] = Inst.u16SignExtend(u16(regs[Inst.reg(args.a)]));
return OutcomeData.ok(r);
};

// ZERO_EXTEND_16
export const zero_extend_16: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = u64(u16(regs[reg(args.a)]));
return ok(r);
regs[Inst.reg(args.b)] = u64(u16(regs[Inst.reg(args.a)]));
return OutcomeData.ok(r);
};

// REVERSE_BYTES
export const reverse_bytes: InstructionRun = (r, args, regs) => {
regs[reg(args.b)] = portable.bswap_u64(regs[reg(args.a)]);
return ok(r);
regs[Inst.reg(args.b)] = portable.bswap_u64(regs[Inst.reg(args.a)]);
return OutcomeData.ok(r);
};
4 changes: 2 additions & 2 deletions assembly/instructions/branch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { newRegisters } from "../registers";
import { Assert, Test, test } from "../test";
import { branch_eq_imm } from "./branch";
import { Outcome, OutcomeData } from "./outcome";
import { reg } from "./utils";
import { Inst } from "./utils";

export const TESTS: Test[] = [
test("branch_eq_imm", () => {
Expand All @@ -15,7 +15,7 @@ export const TESTS: Test[] = [
args.b = 0xfe;
args.c = 0xdeadbeef;
const regs = newRegisters();
regs[reg(args.a)] = 0xfe;
regs[Inst.reg(args.a)] = 0xfe;

const memo = new MemoryBuilder().build();

Expand Down
Loading