added math.mul16_last_upper() to fetch the upper 16 bits of the last word multiplication

This commit is contained in:
Irmen de Jong 2023-09-25 23:59:57 +02:00
parent ae6eeadf54
commit 9b9e6f4af5
4 changed files with 54 additions and 25 deletions

View File

@ -140,6 +140,16 @@ _sinecosR8 .char trunc(127.0 * sin(range(180+45) * rad(360.0/180.0)))
}}
}
asmsub mul16_last_upper() -> uword @AY {
; this routine peeks into the internal 32 bits multiplication result buffer of the
; 16*16 bits multiplication routine, to fetch the upper 16 bits of the last calculation.
%asm {{
lda multiply_words.result+2
ldy multiply_words.result+3
rts
}}
}
sub direction_sc(byte x1, byte y1, byte x2, byte y2) -> ubyte {
; From a pair of signed coordinates around the origin, calculate discrete direction between 0 and 23 into A.
cx16.r0L = 3 ; quadrant

View File

@ -2,6 +2,9 @@
math {
; TODO: the VM doesn't yet store the full 32 bits result of a 16*16 multiplication, so there is NO mul16_last_upper() routine here at this time.
sub sin8u(ubyte angle) -> ubyte {
ubyte[256] sintab = [$80, $83, $86, $89, $8c, $8f, $92, $95, $98, $9b, $9e, $a2, $a5, $a7, $aa, $ad, $b0, $b3, $b6, $b9,
$bc, $be, $c1, $c4, $c6, $c9, $cb, $ce, $d0, $d3, $d5, $d7, $da, $dc, $de, $e0,

View File

@ -1,6 +1,10 @@
TODO
====
- VM: make matn.mul16_last_upper()
- clean up the active file channel assumptions in diskio (basically do chkin every time and not in f_open?)
- return the file channel number from f_open and f_open_w instead of just true (so user can change it and set it back if they want instead of relying on the magic numbers 12 and 13)
OR just add routines to set it back to 12/13 so no tracking has to occur by the user at all
- add a compiler switch to replace all calls to the math word mul routine on the X16 by the verafx call instead.
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
- [on branch: ir-less-branch-opcodes] IR: reduce the number of branch instructions such as BEQ, BEQR, etc (gradually), replace with CMP(I) + status branch instruction

View File

@ -1,38 +1,50 @@
%import textio
%import verafx
;%import verafx
%zeropage basicsafe
%option no_sysinit
main {
sub start() {
const word MULTIPLIER = 431
; verify results:
for value in -50 to 50 {
if value*MULTIPLIER != verafx.muls(value, MULTIPLIER) {
txt.print("verafx muls error\n")
sys.exit(1)
}
}
word value
txt.print("verafx muls...")
cbm.SETTIM(0,0,0)
for value in -50 to 50 {
repeat 250 void verafx.muls(value, MULTIPLIER)
}
txt.print_uw(cbm.RDTIM16())
txt.print_uw(math.mul16_last_upper())
txt.nl()
uword value1=5678
uword value2=9999
uword result = value1*value2
txt.print_uw(result)
txt.spc()
txt.print_uw(math.mul16_last_upper())
txt.nl()
txt.print("6502 muls...")
cbm.SETTIM(0,0,0)
for value in -50 to 50 {
repeat 250 cx16.r0s = value*MULTIPLIER
}
txt.print_uw(cbm.RDTIM16())
txt.nl()
; const word MULTIPLIER = 431
;
; ; verify results:
; for value in -50 to 50 {
; if value*MULTIPLIER != verafx.muls(value, MULTIPLIER) {
; txt.print("verafx muls error\n")
; sys.exit(1)
; }
; }
;
;
; word value
; txt.print("verafx muls...")
; cbm.SETTIM(0,0,0)
; for value in -50 to 50 {
; repeat 250 void verafx.muls(value, MULTIPLIER)
; }
; txt.print_uw(cbm.RDTIM16())
; txt.nl()
;
; txt.print("6502 muls...")
; cbm.SETTIM(0,0,0)
; for value in -50 to 50 {
; repeat 250 cx16.r0s = value*MULTIPLIER
; }
; txt.print_uw(cbm.RDTIM16())
; txt.nl()
}
}