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
24 changes: 24 additions & 0 deletions src/lib/arch/zx48k/runtime/arith/fmul16.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
;; Performs a faster multiply for little 16bit numbs
#include once <arith/mul16.asm>

push namespace core

__FMUL16:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z

cp 33
jp nc, __MUL16_FAST

ld b, l
ld l, h ; HL = 0

1:
add hl, de
djnz 1b
ret

pop namespace
27 changes: 3 additions & 24 deletions src/lib/arch/zx48k/runtime/array.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...


#include once <arith/mul16.asm>
#include once <arith/fmul16.asm>

#ifdef __CHECK_ARRAY_BOUNDARY__
#include once <error.asm>
Expand Down Expand Up @@ -131,7 +131,7 @@ LOOP:

pop de ; DE = Max bound Number (i-th dimension)

call __FNMUL ; HL <= HL * DE mod 65536
call __FMUL16 ; HL <= HL * DE mod 65536
jp LOOP

ARRAY_END:
Expand All @@ -141,7 +141,7 @@ ARRAY_END:
#ifdef __BIG_ARRAY__
ld d, 0
ld e, a
call __FNMUL
call __FMUL16
#else
LOCAL ARRAY_SIZE_LOOP

Expand All @@ -165,27 +165,6 @@ ARRAY_SIZE_LOOP:
push de
ret

;; Performs a faster multiply for little 16bit numbs
LOCAL __FNMUL, __FNMUL2

__FNMUL:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z

cp 33
jp nc, __MUL16_FAST

ld b, l
ld l, h ; HL = 0

__FNMUL2:
add hl, de
djnz __FNMUL2
ret

ENDP

pop namespace
39 changes: 21 additions & 18 deletions tests/functional/arch/zx48k/46.asm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ _b.__DATA__:
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
; What I will do here is to calculate the following sequence:
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
;; Performs a faster multiply for little 16bit numbs
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul16.asm"
push namespace core
__MUL16: ; Mutiplies HL with the last value stored into de stack
; Works for both signed and unsigned
Expand All @@ -119,6 +121,23 @@ __MUL16NOADD:
ret ; Result in hl (16 lower bits)
ENDP
pop namespace
#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
push namespace core
__FMUL16:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z
cp 33
jp nc, __MUL16_FAST
ld b, l
ld l, h ; HL = 0
1:
add hl, de
djnz 1b
ret
pop namespace
#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
push namespace core
Expand Down Expand Up @@ -191,7 +210,7 @@ LOOP:
push de
exx
pop de ; DE = Max bound Number (i-th dimension)
call __FNMUL ; HL <= HL * DE mod 65536
call __FMUL16 ; HL <= HL * DE mod 65536
jp LOOP
ARRAY_END:
ld a, (hl)
Expand All @@ -215,22 +234,6 @@ ARRAY_SIZE_LOOP:
ld de, (RET_ADDR)
push de
ret
;; Performs a faster multiply for little 16bit numbs
LOCAL __FNMUL, __FNMUL2
__FNMUL:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z
cp 33
jp nc, __MUL16_FAST
ld b, l
ld l, h ; HL = 0
__FNMUL2:
add hl, de
djnz __FNMUL2
ret
ENDP
pop namespace
#line 32 "arch/zx48k/46.bas"
Expand Down
39 changes: 21 additions & 18 deletions tests/functional/arch/zx48k/47.asm
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ _test__leave:
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
; What I will do here is to calculate the following sequence:
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
;; Performs a faster multiply for little 16bit numbs
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul16.asm"
push namespace core
__MUL16: ; Mutiplies HL with the last value stored into de stack
; Works for both signed and unsigned
Expand All @@ -124,6 +126,23 @@ __MUL16NOADD:
ret ; Result in hl (16 lower bits)
ENDP
pop namespace
#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
push namespace core
__FMUL16:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z
cp 33
jp nc, __MUL16_FAST
ld b, l
ld l, h ; HL = 0
1:
add hl, de
djnz 1b
ret
pop namespace
#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
push namespace core
Expand Down Expand Up @@ -196,7 +215,7 @@ LOOP:
push de
exx
pop de ; DE = Max bound Number (i-th dimension)
call __FNMUL ; HL <= HL * DE mod 65536
call __FMUL16 ; HL <= HL * DE mod 65536
jp LOOP
ARRAY_END:
ld a, (hl)
Expand All @@ -220,22 +239,6 @@ ARRAY_SIZE_LOOP:
ld de, (RET_ADDR)
push de
ret
;; Performs a faster multiply for little 16bit numbs
LOCAL __FNMUL, __FNMUL2
__FNMUL:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z
cp 33
jp nc, __MUL16_FAST
ld b, l
ld l, h ; HL = 0
__FNMUL2:
add hl, de
djnz __FNMUL2
ret
ENDP
pop namespace
#line 59 "arch/zx48k/47.bas"
Expand Down
39 changes: 21 additions & 18 deletions tests/functional/arch/zx48k/55.asm
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ _b.__DATA__:
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
; What I will do here is to calculate the following sequence:
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
;; Performs a faster multiply for little 16bit numbs
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul16.asm"
push namespace core
__MUL16: ; Mutiplies HL with the last value stored into de stack
; Works for both signed and unsigned
Expand All @@ -112,6 +114,23 @@ __MUL16NOADD:
ret ; Result in hl (16 lower bits)
ENDP
pop namespace
#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
push namespace core
__FMUL16:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z
cp 33
jp nc, __MUL16_FAST
ld b, l
ld l, h ; HL = 0
1:
add hl, de
djnz 1b
ret
pop namespace
#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
push namespace core
Expand Down Expand Up @@ -184,7 +203,7 @@ LOOP:
push de
exx
pop de ; DE = Max bound Number (i-th dimension)
call __FNMUL ; HL <= HL * DE mod 65536
call __FMUL16 ; HL <= HL * DE mod 65536
jp LOOP
ARRAY_END:
ld a, (hl)
Expand All @@ -208,22 +227,6 @@ ARRAY_SIZE_LOOP:
ld de, (RET_ADDR)
push de
ret
;; Performs a faster multiply for little 16bit numbs
LOCAL __FNMUL, __FNMUL2
__FNMUL:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z
cp 33
jp nc, __MUL16_FAST
ld b, l
ld l, h ; HL = 0
__FNMUL2:
add hl, de
djnz __FNMUL2
ret
ENDP
pop namespace
#line 27 "arch/zx48k/55.bas"
Expand Down
39 changes: 21 additions & 18 deletions tests/functional/arch/zx48k/aloadstr1.asm
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ _a.__DATA__:
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
; What I will do here is to calculate the following sequence:
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
;; Performs a faster multiply for little 16bit numbs
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul16.asm"
push namespace core
__MUL16: ; Mutiplies HL with the last value stored into de stack
; Works for both signed and unsigned
Expand All @@ -308,6 +310,23 @@ __MUL16NOADD:
ret ; Result in hl (16 lower bits)
ENDP
pop namespace
#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
push namespace core
__FMUL16:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z
cp 33
jp nc, __MUL16_FAST
ld b, l
ld l, h ; HL = 0
1:
add hl, de
djnz 1b
ret
pop namespace
#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
push namespace core
Expand Down Expand Up @@ -380,7 +399,7 @@ LOOP:
push de
exx
pop de ; DE = Max bound Number (i-th dimension)
call __FNMUL ; HL <= HL * DE mod 65536
call __FMUL16 ; HL <= HL * DE mod 65536
jp LOOP
ARRAY_END:
ld a, (hl)
Expand All @@ -404,22 +423,6 @@ ARRAY_SIZE_LOOP:
ld de, (RET_ADDR)
push de
ret
;; Performs a faster multiply for little 16bit numbs
LOCAL __FNMUL, __FNMUL2
__FNMUL:
xor a
or h
jp nz, __MUL16_FAST
or l
ret z
cp 33
jp nc, __MUL16_FAST
ld b, l
ld l, h ; HL = 0
__FNMUL2:
add hl, de
djnz __FNMUL2
ret
ENDP
pop namespace
#line 27 "arch/zx48k/aloadstr1.bas"
Expand Down
Loading