Skip to content

Commit af00c84

Browse files
committed
optimized fallback llmulhu stackframe
1 parent 5264229 commit af00c84

1 file changed

Lines changed: 43 additions & 41 deletions

File tree

src/crt/llmulhu.src

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ __llmulhu:
103103
jr nz, .L.bit_loop
104104

105105
pop af
106-
jr nc, .L.byte_loop
106+
jr nc, .L.byte_loop
107107

108108
; ld b, d
109109
; ld c, e
@@ -132,59 +132,60 @@ __llmulhu:
132132
; fallback routine that does not disable interrupts or use shadow registers
133133
push ix
134134
push iy
135-
ld ix, -36
136-
add ix, sp
137-
ld sp, ix
138-
lea ix, ix + 36
139135

140-
ld (ix - 3), bc
141-
ld (ix - 6), de
142-
ld (ix - 9), hl
136+
push bc ; ld (ix - 3), bc
137+
push de ; ld (ix - 6), de
138+
push hl ; ld (ix - 9), hl
143139

144-
ld bc, 0
145-
ld (ix - 10), b
146-
ld (ix - 13), bc
147-
ld (ix - 30), bc
148-
ld c, (ix + 12)
149-
ld (ix - 33), bc
150-
ld iy, (ix + 9)
151-
ld (ix - 36), iy
140+
ld c, e ; preserve E
141+
ld ix, -36 + 12 + 9
142+
lea de, ix + 36 - 12 - 9 ; ld de, 0
143+
push de ; ld (ix - 12), $000000
144+
145+
add ix, sp
146+
ld sp, ix
147+
lea ix, ix + 36 - 9
148+
ld (ix - 13), e
149+
push de ; ld (ix - 30), $000000
150+
ld e, (ix + 12)
151+
push de ; ld (ix - 33), de
152+
ld e, c ; restore E
153+
ld bc, (ix + 9)
154+
push bc ; ld (ix - 36), bc
152155

153156
; x_lo * y_lo
154-
ld c, b
155-
ld d, b
156-
inc de
157-
dec.s de
157+
ld c, d
158+
ld b, d
158159
call __llmulu
159-
inc bc
160-
dec.s bc
161-
ld (ix - 16), bc
162160
ld (ix - 19), de
163-
ld b, 0
164-
ld c, b
165-
166-
; x_hi * y_lo
167161
inc.s de
162+
ld e, c
168163
ld d, b
164+
ld (ix - 16), de ; BC, UBC = 0
165+
166+
; x_hi * y_lo
167+
ld d, 0
168+
ld c, d
169+
ld b, d
169170
ld e, (ix - 2)
170171
ld hl, (ix - 5)
171172
call __llmulu
172-
inc bc
173-
dec.s bc
174-
ld (ix - 21), bc
175173
ld (ix - 24), de
174+
inc.s de
175+
ld e, c
176+
ld d, b
177+
ld (ix - 21), de ; BC, UBC = 0
176178
ld (ix - 27), hl
177179

178180
ld c, (ix + 16)
179181
ld (ix - 33), c
180-
ld iy, (ix + 13)
181-
ld (ix - 36), iy
182+
ld bc, (ix + 13)
183+
ld (ix - 36), bc
182184

183185
; x_lo * y_hi
184-
ld b, 0
185-
ld c, b
186-
inc.s de
187-
ld d, b
186+
ld d, 0
187+
ld c, d
188+
ld b, d
188189
ld e, (ix - 6)
189190
ld hl, (ix - 9)
190191
call __llmulu
@@ -196,18 +197,19 @@ __llmulhu:
196197
call .L.__llmulhu_i72add
197198
ld (ix - 16), bc
198199
ld (ix - 19), de
199-
ld bc, 0
200+
inc.s de
201+
ld d, 0
202+
ld c, d
203+
ld b, d
200204

201205
; x_hi * y_hi
202-
inc.s de
203-
ld d, b
204206
ld e, (ix - 2)
205207
ld hl, (ix - 5)
206208
call __llmulu
207-
inc bc
208-
dec.s bc
209209
lea iy, ix - 18
210210
call .L.__llmulhu_i72add
211+
; BC:UDE:UHL = result
212+
; UBC = unknown
211213
ld sp, ix
212214
pop iy
213215
pop ix

0 commit comments

Comments
 (0)