Skip to content

Commit ab9cf1c

Browse files
committed
optimized i48div and tail called negation in signed division routines
1 parent bc3015b commit ab9cf1c

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

src/crt/i48rems.src

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ __i48rems:
2525
lea de, iy
2626
push bc
2727
pop hl
28-
; negate remainder if dividend was negative
29-
call m, __i48neg
3028

3129
pop bc
3230
pop iy
33-
ret
31+
32+
ret p
33+
; negate remainder if dividend was negative
34+
jp __i48neg
3435

3536
extern __i48dvrmu
3637
extern __i48neg
37-
extern __uiyubcNeg
38+
extern __uiyubcNeg

src/crt/lldivs.src

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ __lldivs:
6565
bit 7, (iy + 23)
6666
.div_quotient_skip:
6767

68-
call nz, __llneg
69-
7068
pop iy
7169

72-
ret
70+
ret z
71+
jp __llneg
7372

7473
extern __lldvrmu.hijack
7574
extern __llneg

src/libc/i48div.src

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,37 @@
66

77
; i48div_t i48div(int48_t numer, int48_t denom);
88
_i48div:
9-
; TODO: __i48dvrmu is called twice here
109
push ix
1110
ld ix, 0
1211
add ix, sp
12+
ld c, (ix + 14)
13+
ld b, (ix + 20)
14+
ld a, c
15+
xor a, b
16+
ld a, c
17+
push af
18+
rla
1319
ld hl, (ix + 9)
1420
ld de, (ix + 12)
21+
call c, __i48neg
22+
ld a, b
23+
rla
1524
ld bc, (ix + 15)
1625
ld iy, (ix + 18)
26+
call c, __uiyubcNeg
27+
call __i48dvrmu
1728
ld ix, (ix + 6)
18-
push hl
19-
push de
20-
call __i48divs
29+
pop af
30+
call m, __i48neg
2131
ld (ix + 0), hl
2232
ld (ix + 3), de
23-
pop de
24-
pop hl
25-
call __i48rems
26-
ld (ix + 6), hl
27-
ld (ix + 9), de
33+
rla
34+
call c, __uiyubcNeg
35+
ld (ix + 6), bc
36+
ld (ix + 9), iy
2837
pop ix
2938
ret
3039

31-
extern __i48divs
32-
extern __i48rems
40+
extern __i48dvrmu
41+
extern __i48neg
42+
extern __uiyubcNeg

0 commit comments

Comments
 (0)