Skip to content

Commit 3f82d7a

Browse files
committed
optimized fneg (common case 3F faster, 0.0f/positive subnormal 1F+1 to 1 CC slower)
1 parent 0394937 commit 3f82d7a

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

src/crt/fneg.src

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,23 @@
2323
.type __fneg, @function
2424

2525
__fneg:
26-
or a,a
27-
jr nz,__noexit
26+
; Common case (A != 0) : 5F + 3R + 0W + 2
27+
; A:UBC == 0.0f : 12F + 6R + 3W + 3
28+
; positive subnormal : 14F + 6R + 3W + 3
29+
add a, $7F
30+
inc a
31+
ret po
32+
; input == [+0.0f, +FLT_MIN * 2.0f)
33+
; we need to make sure we do not output -0.0f, so we need to make sure that the mantissa is not zero.
34+
; A is $80 here
35+
rla ; set carry (and set A to $00)
2836
push hl
29-
sbc hl,hl
30-
sbc hl,bc
37+
sbc hl, hl
38+
add hl, bc
3139
pop hl
32-
ret z
33-
__noexit:
34-
xor a,80h
40+
.if 1
41+
; we can optionally return here to make the A:UBC == 0.0f case slightly faster.
42+
ret nc
43+
.endif
44+
rra ; A = (BC != 0) ? $80 : $00
3545
ret

0 commit comments

Comments
 (0)