Add more math fixes

This commit is contained in:
Justine Tunney 2021-03-06 11:41:01 -08:00
parent 11ec99931b
commit bfef17eb6d
27 changed files with 236 additions and 61 deletions

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns arc cosine of 𝑥.
//

View file

@ -17,38 +17,27 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns arc cosine of 𝑥.
//
// @param 𝑥 is an 80-bit long double passed on stack in 16-bytes
// @return result of computation on FPU stack in %st
// @define atan2(abs(sqrt((1-𝑥)*(1+𝑥))),𝑥)
// @define atan2(fabs(sqrt((1-𝑥)*(1+𝑥))),𝑥)
// @domain -1 ≤ 𝑥 ≤ 1
// @mode long,legacy
acosl: push %rbp
acosl: pushq %rbp
mov %rsp,%rbp
.profilable
fldl 16(%rbp)
fld %st
#ifdef __FAST_MATH__
fmul %st(1),%st
fsubrs .Lone(%rip)
fsqrt
#else
fldt 16(%rbp)
fld1
fsubp
fld1
fadd %st(2)
fld %st
fsub %st(2)
fxch
fadd %st(2)
fmulp
fsqrt
fabs # needed in downward rounding mode
#endif
fabs
fxch
fpatan
pop %rbp
leave
ret
.endfn acosl,globl
.rodata.cst4
.Lone: .float 1.0

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns arc sine of 𝑥.
//

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns arc sine of 𝑥.
//

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns arc sine of 𝑥.
//
@ -25,27 +24,18 @@
// @return result of computation on FPU stack in %st
// @define atan2(𝑥,sqrt((1-𝑥)*(1+𝑥)))
// @domain -1 ≤ 𝑥 ≤ 1
// @mode long,legacy
asinl: push %rbp
asinl: pushq %rbp
mov %rsp,%rbp
.profilable
fldl 16(%rbp)
fld %st
#ifdef __FAST_MATH__
fmul %st(1),%st
fsubrs .Lone(%rip)
#else
fldt 16(%rbp)
fld1
fsubp
fld1
fadd %st(2)
fld %st
fsub %st(2)
fxch
fadd %st(2)
fmulp
#endif
fsqrt
fpatan
pop %rbp
fpatan
leave
ret
.endfn asinl,globl
.rodata.cst4
.Lone: .float 1.0

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns arc tangent of 𝑥.
//

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns arc tangent of 𝑥.
//

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns 𝑥^𝑦.
//
@ -27,4 +26,3 @@
pow: ezlea powl,ax
jmp _d2ld2
.endfn pow,globl
.alias pow,__pow_finite

View file

@ -26,4 +26,3 @@
powf: ezlea powl,ax
jmp _f2ld2
.endfn powf,globl
.alias powf,__powf_finite

View file

@ -18,6 +18,13 @@
*/
#include "libc/math.h"
long double __powl_finite(long double x, long double y) {
return powl(x, y);
#define powl __powl_finite
#include "libc/tinymath/powl.c"
double __pow_finite(double x, double y) {
return __powl_finite(x, y);
}
float __powf_finite(float x, float y) {
return __powl_finite(x, y);
}

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns 𝑥 × 2ʸ.
//

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns sine of 𝑥.
//

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns sine and cosine of 𝑥.
//

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns sine and cosine of 𝑥.
//

View file

@ -18,7 +18,6 @@
*/
#include "libc/runtime/pc.internal.h"
#include "libc/macros.internal.h"
.source __FILE__
// Returns sine and cosine of 𝑥.
//

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns sine of 𝑥.
//

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
.source __FILE__
// Returns tangent of 𝑥.
//

View file

@ -18,7 +18,6 @@
*/
#include "libc/runtime/pc.internal.h"
#include "libc/macros.internal.h"
.source __FILE__
// Returns tangent of 𝑥.
//

View file

@ -40,6 +40,10 @@ $(LIBC_TINYMATH_A).pkg: \
$(LIBC_TINYMATH_A_OBJS) \
$(foreach x,$(LIBC_TINYMATH_A_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/libc/tinymath/powfin.o: \
OVERRIDE_CFLAGS += \
-ffast-math
LIBC_TINYMATH_LIBS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)))
LIBC_TINYMATH_HDRS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)_HDRS))
LIBC_TINYMATH_SRCS = $(foreach x,$(LIBC_TINYMATH_ARTIFACTS),$($(x)_SRCS))