diff --git a/src/libc/cosf.src b/src/libc/cosf.src deleted file mode 100644 index c654c601b..000000000 --- a/src/libc/cosf.src +++ /dev/null @@ -1,32 +0,0 @@ - .assume adl=1 - - .section .text - .global _cos - .type _cos, @function - .global _cosf - .type _cosf, @function - -.ifdef PREFER_OS_LIBC - - .set _cosf, 0x02211C - .set _cos, _cosf - -.else - -; float _f32_sinus(int quad, float arg) -_cos: -_cosf: - call __frameset0 - ld e, (ix + 9) ; exponent - ld hl, (ix + 6) ; mantissa - res 7, e ; fabsf(x) - push de - push hl - scf ; quad 1, N reset, C set - push af - jp _sinf.hijack - - .extern __frameset0 - .extern _sinf.hijack - -.endif diff --git a/src/libc/sinf.c b/src/libc/sincosf.c similarity index 100% rename from src/libc/sinf.c rename to src/libc/sincosf.c diff --git a/src/libc/sincosf.src b/src/libc/sincosf.src new file mode 100644 index 000000000..7abd29b48 --- /dev/null +++ b/src/libc/sincosf.src @@ -0,0 +1,93 @@ + .assume adl=1 + + .section .text + + .global _sinf + .type _sinf, @function + .global _sin + .type _sin, @function + +.ifdef PREFER_OS_LIBC + + .set _sinf, 0x022118 + .set _sin, _sinf + +.else + +; float _f32_sinus(int quad, float arg) +_sin: +_sinf: + ld hl, 6 + add hl, sp + ld e, (hl) ; exponent + dec hl + dec hl + dec hl + ld hl, (hl) ; mantissa + ld a, e + add a, a ; clear signbit + sub a, 117 ; |x| < 2^-10 or 0x3affffff + ret c ; sin(x) = x for small arguments + ld a, e + res 7, e ; x = fabsf(x) + push de ; exponent + push hl ; mantissa + rlca + add a, a + ld e, a + push de + .local _sinf.hijack +_sinf.hijack: + call __f32_sinus + pop bc + pop bc + pop bc + ; you can ret here if clamping is not needed + ; clamp the result to [-1.0, +1.0] + ld a, e + add a, a + sub a, 126 + ret nz ; |y| < 0.5f + push hl + add hl, hl + pop hl + ret nc ; |y| < 1.0f + ld l, h ; zero out the lower 8 bits of the mantissa + ret + + .extern __f32_sinus + +.endif + + .section .text + + .global _cosf + .type _cosf, @function + .global _cos + .type _cos, @function + +.ifdef PREFER_OS_LIBC + + .set _cosf, 0x02211C + .set _cos, _cosf + +.else + +; float _f32_sinus(int quad, float arg) +_cos: +_cosf: + ld hl, 6 + add hl, sp + ld e, (hl) ; exponent + dec hl + dec hl + dec hl + ld hl, (hl) ; mantissa + res 7, e ; fabsf(x) + push de + push hl + scf ; quad 1, N reset, C set + push af + jr _sinf.hijack + +.endif diff --git a/src/libc/sinf.src b/src/libc/sinf.src deleted file mode 100644 index 45d7c09d5..000000000 --- a/src/libc/sinf.src +++ /dev/null @@ -1,58 +0,0 @@ - .assume adl=1 - - .section .text - - .global _sinf - .type _sinf, @function - .global _sin - .type _sin, @function - -.ifdef PREFER_OS_LIBC - - .set _sinf, 0x022118 - .set _sin, _sinf - -.else - - .global _sinf.hijack - -; float _f32_sinus(int quad, float arg) -_sin: -_sinf: - call __frameset0 - ld e, (ix + 9) ; exponent - ld hl, (ix + 6) ; mantissa - ld a, e - add a, a ; clear signbit - sub a, 117 ; |x| < 2^-10 or 0x3affffff - jr c, _sinf.small_arg - ld a, e - res 7, e ; x = fabsf(x) - push de ; exponent - push hl ; mantissa - rlca - add a, a - ld e, a - push de -_sinf.hijack: - call __f32_sinus -_sinf.small_arg: - ld sp, ix - pop ix - ; you can ret here if clamping is not needed - ; clamp the result to [-1.0, +1.0] - ld a, e - add a, a - sub a, 126 - ret nz ; |y| < 0.5f - push hl - add hl, hl - pop hl - ret nc ; |y| < 1.0f - ld l, h ; zero out the lower 8 bits of the mantissa - ret - - .extern __frameset0 - .extern __f32_sinus - -.endif