Open mmoskal opened 1 year ago
Utility script so it doesn't get lost:
devs build -F allFunctions -F allPrototypes devs/run-tests/allcompile.ts
devs disasm -d > all.dasm
node analyze-bytecode.ts all.dasm
import { readFileSync } from "node:fs"
const OP_PRINT_FMTS = [
// from bytecode.ts
]
const seqs = {
1: {},
2: {},
3: {},
}
let lines = 0
let size = 0
for (const line of readFileSync(process.argv[2], "utf8").split(/\n/)) {
const m = /^\s*\d+:\s*.*\/\/ ([0-9a-f]+)/.exec(line)
if (m) {
lines++
const buf = Buffer.from(m[1], "hex")
size += buf.length
for (let i = 0; i < buf.length; i++) {
for (const lens of Object.keys(seqs)) {
const len = +lens
const seq = buf.slice(i, i + len)
if (seq.length == len) {
const s = seq.toString("hex")
if (!seqs[lens][s]) seqs[lens][s] = 0
seqs[lens][s]++
}
}
}
}
}
function show(map) {
for (const [k, v] of Object.entries(map)
.sort((a, b) => a[1] - b[1])
.slice(-100)) {
const buf = Buffer.from(k, "hex")
const op = OP_PRINT_FMTS[buf[0]]
console.log(k, v, op)
}
}
show(seqs[2])
console.log({ lines, size })
These should make the generated bytecode a little smaller.
Approximate size reductions are give here for "allcompile.ts" - 68k binary with 38k of function code (and 6k of fonts).
ALLOC_*
opcodes to expressionslength
field from function descriptor (just assume it runs until the next function) (2.3k)load_local(0...3)
-> single opcode each - (3.5k)static_ascii_string_high(n)
(==static_ascii_string(n+0xf8)
) ? (~1k?)ascii_field_high
?allcompile.ts
) and add them tobytecode.md