Skip to content

Commit 71b567f

Browse files
authored
Merge pull request #949 from boriel-basic/feature/optimize_1d_arrays
refact: refactorize array.asm runtime
2 parents 620b073 + a9e53a9 commit 71b567f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1136
-973
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
;; Performs a faster multiply for little 16bit numbs
2+
#include once <arith/mul16.asm>
3+
4+
push namespace core
5+
6+
__FMUL16:
7+
xor a
8+
or h
9+
jp nz, __MUL16_FAST
10+
or l
11+
ret z
12+
13+
cp 33
14+
jp nc, __MUL16_FAST
15+
16+
ld b, l
17+
ld l, h ; HL = 0
18+
19+
1:
20+
add hl, de
21+
djnz 1b
22+
ret
23+
24+
pop namespace

src/lib/arch/zx48k/runtime/array.asm

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
1717

1818

19-
#include once <arith/mul16.asm>
19+
#include once <arith/fmul16.asm>
2020

2121
#ifdef __CHECK_ARRAY_BOUNDARY__
2222
#include once <error.asm>
@@ -131,7 +131,7 @@ LOOP:
131131

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

134-
call __FNMUL ; HL <= HL * DE mod 65536
134+
call __FMUL16 ; HL <= HL * DE mod 65536
135135
jp LOOP
136136

137137
ARRAY_END:
@@ -141,7 +141,7 @@ ARRAY_END:
141141
#ifdef __BIG_ARRAY__
142142
ld d, 0
143143
ld e, a
144-
call __FNMUL
144+
call __FMUL16
145145
#else
146146
LOCAL ARRAY_SIZE_LOOP
147147

@@ -165,27 +165,6 @@ ARRAY_SIZE_LOOP:
165165
push de
166166
ret
167167

168-
;; Performs a faster multiply for little 16bit numbs
169-
LOCAL __FNMUL, __FNMUL2
170-
171-
__FNMUL:
172-
xor a
173-
or h
174-
jp nz, __MUL16_FAST
175-
or l
176-
ret z
177-
178-
cp 33
179-
jp nc, __MUL16_FAST
180-
181-
ld b, l
182-
ld l, h ; HL = 0
183-
184-
__FNMUL2:
185-
add hl, de
186-
djnz __FNMUL2
187-
ret
188-
189168
ENDP
190169

191170
pop namespace

tests/functional/arch/zx48k/46.asm

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ _b.__DATA__:
9393
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
9494
; What I will do here is to calculate the following sequence:
9595
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
96-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm"
96+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
97+
;; Performs a faster multiply for little 16bit numbs
98+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul16.asm"
9799
push namespace core
98100
__MUL16: ; Mutiplies HL with the last value stored into de stack
99101
; Works for both signed and unsigned
@@ -119,6 +121,23 @@ __MUL16NOADD:
119121
ret ; Result in hl (16 lower bits)
120122
ENDP
121123
pop namespace
124+
#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
125+
push namespace core
126+
__FMUL16:
127+
xor a
128+
or h
129+
jp nz, __MUL16_FAST
130+
or l
131+
ret z
132+
cp 33
133+
jp nc, __MUL16_FAST
134+
ld b, l
135+
ld l, h ; HL = 0
136+
1:
137+
add hl, de
138+
djnz 1b
139+
ret
140+
pop namespace
122141
#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
123142
#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
124143
push namespace core
@@ -191,7 +210,7 @@ LOOP:
191210
push de
192211
exx
193212
pop de ; DE = Max bound Number (i-th dimension)
194-
call __FNMUL ; HL <= HL * DE mod 65536
213+
call __FMUL16 ; HL <= HL * DE mod 65536
195214
jp LOOP
196215
ARRAY_END:
197216
ld a, (hl)
@@ -215,22 +234,6 @@ ARRAY_SIZE_LOOP:
215234
ld de, (RET_ADDR)
216235
push de
217236
ret
218-
;; Performs a faster multiply for little 16bit numbs
219-
LOCAL __FNMUL, __FNMUL2
220-
__FNMUL:
221-
xor a
222-
or h
223-
jp nz, __MUL16_FAST
224-
or l
225-
ret z
226-
cp 33
227-
jp nc, __MUL16_FAST
228-
ld b, l
229-
ld l, h ; HL = 0
230-
__FNMUL2:
231-
add hl, de
232-
djnz __FNMUL2
233-
ret
234237
ENDP
235238
pop namespace
236239
#line 32 "arch/zx48k/46.bas"

tests/functional/arch/zx48k/47.asm

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ _test__leave:
9898
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
9999
; What I will do here is to calculate the following sequence:
100100
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
101-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm"
101+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
102+
;; Performs a faster multiply for little 16bit numbs
103+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul16.asm"
102104
push namespace core
103105
__MUL16: ; Mutiplies HL with the last value stored into de stack
104106
; Works for both signed and unsigned
@@ -124,6 +126,23 @@ __MUL16NOADD:
124126
ret ; Result in hl (16 lower bits)
125127
ENDP
126128
pop namespace
129+
#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
130+
push namespace core
131+
__FMUL16:
132+
xor a
133+
or h
134+
jp nz, __MUL16_FAST
135+
or l
136+
ret z
137+
cp 33
138+
jp nc, __MUL16_FAST
139+
ld b, l
140+
ld l, h ; HL = 0
141+
1:
142+
add hl, de
143+
djnz 1b
144+
ret
145+
pop namespace
127146
#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
128147
#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
129148
push namespace core
@@ -196,7 +215,7 @@ LOOP:
196215
push de
197216
exx
198217
pop de ; DE = Max bound Number (i-th dimension)
199-
call __FNMUL ; HL <= HL * DE mod 65536
218+
call __FMUL16 ; HL <= HL * DE mod 65536
200219
jp LOOP
201220
ARRAY_END:
202221
ld a, (hl)
@@ -220,22 +239,6 @@ ARRAY_SIZE_LOOP:
220239
ld de, (RET_ADDR)
221240
push de
222241
ret
223-
;; Performs a faster multiply for little 16bit numbs
224-
LOCAL __FNMUL, __FNMUL2
225-
__FNMUL:
226-
xor a
227-
or h
228-
jp nz, __MUL16_FAST
229-
or l
230-
ret z
231-
cp 33
232-
jp nc, __MUL16_FAST
233-
ld b, l
234-
ld l, h ; HL = 0
235-
__FNMUL2:
236-
add hl, de
237-
djnz __FNMUL2
238-
ret
239242
ENDP
240243
pop namespace
241244
#line 59 "arch/zx48k/47.bas"

tests/functional/arch/zx48k/55.asm

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ _b.__DATA__:
8686
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
8787
; What I will do here is to calculate the following sequence:
8888
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
89-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm"
89+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
90+
;; Performs a faster multiply for little 16bit numbs
91+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul16.asm"
9092
push namespace core
9193
__MUL16: ; Mutiplies HL with the last value stored into de stack
9294
; Works for both signed and unsigned
@@ -112,6 +114,23 @@ __MUL16NOADD:
112114
ret ; Result in hl (16 lower bits)
113115
ENDP
114116
pop namespace
117+
#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
118+
push namespace core
119+
__FMUL16:
120+
xor a
121+
or h
122+
jp nz, __MUL16_FAST
123+
or l
124+
ret z
125+
cp 33
126+
jp nc, __MUL16_FAST
127+
ld b, l
128+
ld l, h ; HL = 0
129+
1:
130+
add hl, de
131+
djnz 1b
132+
ret
133+
pop namespace
115134
#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
116135
#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
117136
push namespace core
@@ -184,7 +203,7 @@ LOOP:
184203
push de
185204
exx
186205
pop de ; DE = Max bound Number (i-th dimension)
187-
call __FNMUL ; HL <= HL * DE mod 65536
206+
call __FMUL16 ; HL <= HL * DE mod 65536
188207
jp LOOP
189208
ARRAY_END:
190209
ld a, (hl)
@@ -208,22 +227,6 @@ ARRAY_SIZE_LOOP:
208227
ld de, (RET_ADDR)
209228
push de
210229
ret
211-
;; Performs a faster multiply for little 16bit numbs
212-
LOCAL __FNMUL, __FNMUL2
213-
__FNMUL:
214-
xor a
215-
or h
216-
jp nz, __MUL16_FAST
217-
or l
218-
ret z
219-
cp 33
220-
jp nc, __MUL16_FAST
221-
ld b, l
222-
ld l, h ; HL = 0
223-
__FNMUL2:
224-
add hl, de
225-
djnz __FNMUL2
226-
ret
227230
ENDP
228231
pop namespace
229232
#line 27 "arch/zx48k/55.bas"

tests/functional/arch/zx48k/aloadstr1.asm

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ _a.__DATA__:
282282
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
283283
; What I will do here is to calculate the following sequence:
284284
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
285-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm"
285+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
286+
;; Performs a faster multiply for little 16bit numbs
287+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul16.asm"
286288
push namespace core
287289
__MUL16: ; Mutiplies HL with the last value stored into de stack
288290
; Works for both signed and unsigned
@@ -308,6 +310,23 @@ __MUL16NOADD:
308310
ret ; Result in hl (16 lower bits)
309311
ENDP
310312
pop namespace
313+
#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arith/fmul16.asm"
314+
push namespace core
315+
__FMUL16:
316+
xor a
317+
or h
318+
jp nz, __MUL16_FAST
319+
or l
320+
ret z
321+
cp 33
322+
jp nc, __MUL16_FAST
323+
ld b, l
324+
ld l, h ; HL = 0
325+
1:
326+
add hl, de
327+
djnz 1b
328+
ret
329+
pop namespace
311330
#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
312331
#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm"
313332
push namespace core
@@ -380,7 +399,7 @@ LOOP:
380399
push de
381400
exx
382401
pop de ; DE = Max bound Number (i-th dimension)
383-
call __FNMUL ; HL <= HL * DE mod 65536
402+
call __FMUL16 ; HL <= HL * DE mod 65536
384403
jp LOOP
385404
ARRAY_END:
386405
ld a, (hl)
@@ -404,22 +423,6 @@ ARRAY_SIZE_LOOP:
404423
ld de, (RET_ADDR)
405424
push de
406425
ret
407-
;; Performs a faster multiply for little 16bit numbs
408-
LOCAL __FNMUL, __FNMUL2
409-
__FNMUL:
410-
xor a
411-
or h
412-
jp nz, __MUL16_FAST
413-
or l
414-
ret z
415-
cp 33
416-
jp nc, __MUL16_FAST
417-
ld b, l
418-
ld l, h ; HL = 0
419-
__FNMUL2:
420-
add hl, de
421-
djnz __FNMUL2
422-
ret
423426
ENDP
424427
pop namespace
425428
#line 27 "arch/zx48k/aloadstr1.bas"

0 commit comments

Comments
 (0)