mandel-6502/tables.js
Jamey Sharp aee587388d eliminate mul_hibyte512 table
This costs an extra half cycle on average, assuming uniform distribution
of multiplication inputs. I don't think a half cycle is worth an extra
256-byte table.
2024-12-31 02:01:45 -08:00

40 lines
716 B
JavaScript

function db(func) {
let lines = [];
for (let i = 0; i < 256; i += 16) {
let items = [];
for (let j = 0; j < 16; j++) {
let x = i + j;
items.push(func(x));
}
lines.push(' .byte ' + items.join(', '));
}
return lines.join('\n');
}
console.log(
`.segment "TABLES"
.export mul_lobyte
.export mul_hibyte
.export sqr_lobyte
.export sqr_hibyte
; (i * i) / 2 for the multiplier
.align 256
mul_lobyte:
${db((i) => ((i * i) >> 1) & 0xff)}
.align 256
mul_hibyte:
${db((i) => ((i * i) >> 9) & 0xff)}
; (i * i) for the plain squares
.align 256
sqr_lobyte:
${db((i) => (i * i) & 0xff)}
.align 256
sqr_hibyte:
${db((i) => ((i * i) >> 8) & 0xff)}
`);