Skip to content

Commit 65392f1

Browse files
ZERICO2005runer112
andcommitted
optimize ceil(A:UHL / 512) (runner112)
Co-authored-by: Zachary Wassall <runer112@gmail.com>
1 parent 93fed26 commit 65392f1

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/fatdrvce/fatdrvce.asm

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,25 +2519,26 @@ util_ceil_byte_size_to_block_size:
25192519
; - A = 0
25202520
; destroys:
25212521
; - BC, flags
2522-
compare_auhl_zero
2522+
2523+
; if A:UHL == 0, abort
2524+
compare_hl_zero
2525+
jr nz, .dec_hl
2526+
or a, a
25232527
ret z
2524-
; test if the low 9 bits are non-zero
2525-
inc l
2526-
dec l
2527-
jr nz,.round_up
2528-
bit 0,h
2529-
.round_up:
2530-
push af
2528+
; A:UHL--
2529+
dec a
2530+
.dec_hl:
2531+
dec hl
2532+
2533+
; A:UHL /= 512
25312534
push hl
25322535
pop bc
25332536
ld l,9
25342537
call ti._lshru
25352538
push bc
25362539
pop hl
2537-
pop af
2538-
ld a,0
2539-
ret z
2540-
; round up
2540+
2541+
; A:UHL++
25412542
inc hl
25422543
ret
25432544

0 commit comments

Comments
 (0)