Skip to content

Commit 8341c4b

Browse files
committed
move sinf/cosf into the same file and optimized the stack frame
1 parent 4fb8622 commit 8341c4b

4 files changed

Lines changed: 93 additions & 90 deletions

File tree

src/libc/cosf.src

Lines changed: 0 additions & 32 deletions
This file was deleted.
File renamed without changes.

src/libc/sincosf.src

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.assume adl=1
2+
3+
.section .text
4+
5+
.global _sinf
6+
.type _sinf, @function
7+
.global _sin
8+
.type _sin, @function
9+
10+
.ifdef PREFER_OS_LIBC
11+
12+
.set _sinf, 0x022118
13+
.set _sin, _sinf
14+
15+
.else
16+
17+
; float _f32_sinus(int quad, float arg)
18+
_sin:
19+
_sinf:
20+
ld hl, 6
21+
add hl, sp
22+
ld e, (hl) ; exponent
23+
dec hl
24+
dec hl
25+
dec hl
26+
ld hl, (hl) ; mantissa
27+
ld a, e
28+
add a, a ; clear signbit
29+
sub a, 117 ; |x| < 2^-10 or 0x3affffff
30+
ret c ; sin(x) = x for small arguments
31+
ld a, e
32+
res 7, e ; x = fabsf(x)
33+
push de ; exponent
34+
push hl ; mantissa
35+
rlca
36+
add a, a
37+
ld e, a
38+
push de
39+
.local _sinf.hijack
40+
_sinf.hijack:
41+
call __f32_sinus
42+
pop bc
43+
pop bc
44+
pop bc
45+
; you can ret here if clamping is not needed
46+
; clamp the result to [-1.0, +1.0]
47+
ld a, e
48+
add a, a
49+
sub a, 126
50+
ret nz ; |y| < 0.5f
51+
push hl
52+
add hl, hl
53+
pop hl
54+
ret nc ; |y| < 1.0f
55+
ld l, h ; zero out the lower 8 bits of the mantissa
56+
ret
57+
58+
.extern __f32_sinus
59+
60+
.endif
61+
62+
.section .text
63+
64+
.global _cosf
65+
.type _cosf, @function
66+
.global _cos
67+
.type _cos, @function
68+
69+
.ifdef PREFER_OS_LIBC
70+
71+
.set _cosf, 0x02211C
72+
.set _cos, _cosf
73+
74+
.else
75+
76+
; float _f32_sinus(int quad, float arg)
77+
_cos:
78+
_cosf:
79+
ld hl, 6
80+
add hl, sp
81+
ld e, (hl) ; exponent
82+
dec hl
83+
dec hl
84+
dec hl
85+
ld hl, (hl) ; mantissa
86+
res 7, e ; fabsf(x)
87+
push de
88+
push hl
89+
scf ; quad 1, N reset, C set
90+
push af
91+
jr _sinf.hijack
92+
93+
.endif

src/libc/sinf.src

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)