From 71ff3830df5bb175e94a73d5187cea93d87fa5bc Mon Sep 17 00:00:00 2001 From: Koki Ueha Date: Sun, 1 Jun 2025 11:25:51 +0000 Subject: [PATCH] libc: replace MinGW's trigonometric functions with compiler_rt's - sinf - cosf - sincos - sincosf - tanf --- lib/libc/mingw/math/arm/sincos.S | 3 -- lib/libc/mingw/math/arm/sincosf.S | 29 ---------------- lib/libc/mingw/math/arm64/sincos.S | 3 -- lib/libc/mingw/math/arm64/sincosf.S | 31 ----------------- lib/libc/mingw/math/x86/cosf.c | 11 ------ lib/libc/mingw/math/x86/cossin.c | 52 ----------------------------- lib/libc/mingw/math/x86/sinf.c | 11 ------ lib/libc/mingw/math/x86/tanf.c | 11 ------ src/libs/mingw.zig | 6 ---- 9 files changed, 157 deletions(-) delete mode 100644 lib/libc/mingw/math/arm/sincosf.S delete mode 100644 lib/libc/mingw/math/arm64/sincosf.S delete mode 100644 lib/libc/mingw/math/x86/cosf.c delete mode 100644 lib/libc/mingw/math/x86/cossin.c delete mode 100644 lib/libc/mingw/math/x86/sinf.c delete mode 100644 lib/libc/mingw/math/x86/tanf.c diff --git a/lib/libc/mingw/math/arm/sincos.S b/lib/libc/mingw/math/arm/sincos.S index 2d3caa8fe2..d517f4cd55 100644 --- a/lib/libc/mingw/math/arm/sincos.S +++ b/lib/libc/mingw/math/arm/sincos.S @@ -8,11 +8,8 @@ .file "sincos.S" .text .align 2 - .globl __MINGW_USYMBOL(sincos) .globl __MINGW_USYMBOL(sincosl) - .def __MINGW_USYMBOL(sincos); .scl 2; .type 32; .endef .def __MINGW_USYMBOL(sincosl); .scl 2; .type 32; .endef -__MINGW_USYMBOL(sincos): __MINGW_USYMBOL(sincosl): push {r4, r5, r11, lr} add r11, sp, #8 diff --git a/lib/libc/mingw/math/arm/sincosf.S b/lib/libc/mingw/math/arm/sincosf.S deleted file mode 100644 index ce88b18ba7..0000000000 --- a/lib/libc/mingw/math/arm/sincosf.S +++ /dev/null @@ -1,29 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the mingw-w64 runtime package. - * No warranty is given; refer to the file DISCLAIMER.PD within this package. - */ -#include <_mingw_mac.h> - - .file "sincosf.S" - .text - .align 2 - .globl __MINGW_USYMBOL(sincosf) - .def __MINGW_USYMBOL(sincosf); .scl 2; .type 32; .endef -__MINGW_USYMBOL(sincosf): - push {r4, r5, r11, lr} - add r11, sp, #8 - vpush {d8} - - mov r4, r0 - mov r5, r1 - vmov.f32 s16, s0 - bl sinf - vstr s0, [r4] - - vmov.f32 s0, s16 - bl cosf - vstr s0, [r5] - - vpop {d8} - pop {r4, r5, r11, pc} diff --git a/lib/libc/mingw/math/arm64/sincos.S b/lib/libc/mingw/math/arm64/sincos.S index f7ae446aa6..ba0854b78a 100644 --- a/lib/libc/mingw/math/arm64/sincos.S +++ b/lib/libc/mingw/math/arm64/sincos.S @@ -8,11 +8,8 @@ .file "sincos.S" .text .align 2 - .globl __MINGW_USYMBOL(sincos) .globl __MINGW_USYMBOL(sincosl) - .def __MINGW_USYMBOL(sincos); .scl 2; .type 32; .endef .def __MINGW_USYMBOL(sincosl); .scl 2; .type 32; .endef -__MINGW_USYMBOL(sincos): __MINGW_USYMBOL(sincosl): str d8, [sp, #-32]! str x30, [sp, #8] diff --git a/lib/libc/mingw/math/arm64/sincosf.S b/lib/libc/mingw/math/arm64/sincosf.S deleted file mode 100644 index 6939eeb8da..0000000000 --- a/lib/libc/mingw/math/arm64/sincosf.S +++ /dev/null @@ -1,31 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the mingw-w64 runtime package. - * No warranty is given; refer to the file DISCLAIMER.PD within this package. - */ -#include <_mingw_mac.h> - - .file "sincosf.S" - .text - .align 2 - .globl __MINGW_USYMBOL(sincosf) - .def __MINGW_USYMBOL(sincosf); .scl 2; .type 32; .endef -__MINGW_USYMBOL(sincosf): - str d8, [sp, #-32]! - str x30, [sp, #8] - stp x19, x20, [sp, #16] - - mov x19, x0 - mov x20, x1 - fmov s8, s0 - bl sinf - str s0, [x19] - - fmov s0, s8 - bl cosf - str s0, [x20] - - ldp x19, x20, [sp, #16] - ldr x30, [sp, #8] - ldr d8, [sp], #32 - ret diff --git a/lib/libc/mingw/math/x86/cosf.c b/lib/libc/mingw/math/x86/cosf.c deleted file mode 100644 index 41e2c774ce..0000000000 --- a/lib/libc/mingw/math/x86/cosf.c +++ /dev/null @@ -1,11 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the mingw-w64 runtime package. - * No warranty is given; refer to the file DISCLAIMER.PD within this package. - */ -#include - -float cosf(float _X) -{ - return ((float)cos((double)_X)); -} diff --git a/lib/libc/mingw/math/x86/cossin.c b/lib/libc/mingw/math/x86/cossin.c deleted file mode 100644 index b86fbfc9e8..0000000000 --- a/lib/libc/mingw/math/x86/cossin.c +++ /dev/null @@ -1,52 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the mingw-w64 runtime package. - * No warranty is given; refer to the file DISCLAIMER.PD within this package. - */ - -void sincos (double __x, double *p_sin, double *p_cos); -void sincosf (float __x, float *p_sin, float *p_cos); - -void sincos (double __x, double *p_sin, double *p_cos) -{ - long double c, s; - - __asm__ __volatile__ ("fsincos\n\t" - "fnstsw %%ax\n\t" - "testl $0x400, %%eax\n\t" - "jz 1f\n\t" - "fldpi\n\t" - "fadd %%st(0)\n\t" - "fxch %%st(1)\n\t" - "2: fprem1\n\t" - "fnstsw %%ax\n\t" - "testl $0x400, %%eax\n\t" - "jnz 2b\n\t" - "fstp %%st(1)\n\t" - "fsincos\n\t" - "1:" : "=t" (c), "=u" (s) : "0" (__x) : "eax"); - *p_sin = (double) s; - *p_cos = (double) c; -} - -void sincosf (float __x, float *p_sin, float *p_cos) -{ - long double c, s; - - __asm__ __volatile__ ("fsincos\n\t" - "fnstsw %%ax\n\t" - "testl $0x400, %%eax\n\t" - "jz 1f\n\t" - "fldpi\n\t" - "fadd %%st(0)\n\t" - "fxch %%st(1)\n\t" - "2: fprem1\n\t" - "fnstsw %%ax\n\t" - "testl $0x400, %%eax\n\t" - "jnz 2b\n\t" - "fstp %%st(1)\n\t" - "fsincos\n\t" - "1:" : "=t" (c), "=u" (s) : "0" (__x) : "eax"); - *p_sin = (float) s; - *p_cos = (float) c; -} diff --git a/lib/libc/mingw/math/x86/sinf.c b/lib/libc/mingw/math/x86/sinf.c deleted file mode 100644 index 29fd3a2a82..0000000000 --- a/lib/libc/mingw/math/x86/sinf.c +++ /dev/null @@ -1,11 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the mingw-w64 runtime package. - * No warranty is given; refer to the file DISCLAIMER.PD within this package. - */ -#include - -float sinf(float _X) -{ - return ((float) sin ((double) _X)); -} diff --git a/lib/libc/mingw/math/x86/tanf.c b/lib/libc/mingw/math/x86/tanf.c deleted file mode 100644 index 72b4cc4bbb..0000000000 --- a/lib/libc/mingw/math/x86/tanf.c +++ /dev/null @@ -1,11 +0,0 @@ -/** - * This file has no copyright assigned and is placed in the Public Domain. - * This file is part of the mingw-w64 runtime package. - * No warranty is given; refer to the file DISCLAIMER.PD within this package. - */ -#include - -float tanf(float _X) -{ - return ((float)tan((double)_X)); -} diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig index 3b6404516a..8b5197a43b 100644 --- a/src/libs/mingw.zig +++ b/src/libs/mingw.zig @@ -916,7 +916,6 @@ const mingw32_x86_src = [_][]const u8{ "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "copysignl.S", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cosl.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cosl_internal.S", - "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cossin.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cossinl.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "exp2l.S", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "expl.c", @@ -965,11 +964,8 @@ const mingw32_x86_32_src = [_][]const u8{ "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atan2f.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atanf.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "ceilf.S", - "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cosf.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "floorf.S", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "fmodf.c", - "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "sinf.c", - "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "tanf.c", }; const mingw32_arm_src = [_][]const u8{ @@ -983,7 +979,6 @@ const mingw32_arm32_src = [_][]const u8{ "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "s_rint.c", "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "s_rintf.c", "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "sincos.S", - "math" ++ path.sep_str ++ "arm" ++ path.sep_str ++ "sincosf.S", }; const mingw32_arm64_src = [_][]const u8{ @@ -992,7 +987,6 @@ const mingw32_arm64_src = [_][]const u8{ "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "rint.c", "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "rintf.c", "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "sincos.S", - "math" ++ path.sep_str ++ "arm64" ++ path.sep_str ++ "sincosf.S", }; const mingw32_winpthreads_src = [_][]const u8{