forked from brooke/mandel-6502
Faster imul16 routine
Improves runtime from 16.24 ms/px to 14.44 ms/px This uses a routine found on Everything2: https://everything2.com/title/Fast+6502+multiplication which uses a lookup table of squares to do 8-bit imuls, which are then composed into a 16-bit imul
This commit is contained in:
parent
29630c8887
commit
5637783529
5 changed files with 183 additions and 81 deletions
38
tables.js
Normal file
38
tables.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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');
|
||||
}
|
||||
|
||||
let squares = [];
|
||||
for (let i = 0; i < 512; i++) {
|
||||
squares.push(Math.trunc((i * i + 1) / 2));
|
||||
}
|
||||
|
||||
console.log(
|
||||
`.segment "TABLES"
|
||||
|
||||
.export mul_lobyte256
|
||||
.export mul_hibyte256
|
||||
.export mul_hibyte512
|
||||
|
||||
.align 256
|
||||
mul_lobyte256:
|
||||
${db((i) => squares[i] & 0xff)}
|
||||
|
||||
.align 256
|
||||
mul_hibyte256:
|
||||
${db((i) => (squares[i] >> 8) & 0xff)}
|
||||
|
||||
.align 256
|
||||
mul_hibyte512:
|
||||
${db((i) => (squares[i + 256] >> 8) & 0xff)}
|
||||
|
||||
`);
|
||||
Loading…
Add table
Add a link
Reference in a new issue