diff --git a/lib/c/math.zig b/lib/c/math.zig index 8282b1ff0ab772d40b160f7dd2897910456c1504..3e4aa662d09ccde4b42ccdb48dfc08e19edd0154 100644 --- a/lib/c/math.zig +++ b/lib/c/math.zig @@ -32,6 +32,12 @@ comptime { @export(&nanf, .{ .name = "nanf", .linkage = common.linkage, .visibility = common.visibility }); @export(&nanl, .{ .name = "nanl", .linkage = common.linkage, .visibility = common.visibility }); } + + if (builtin.target.isMuslLibC()) { + @export(©signf, .{ .name = "copysignf", .linkage = common.linkage, .visibility = common.visibility }); + @export(©sign, .{ .name = "copysign", .linkage = common.linkage, .visibility = common.visibility }); + } + @export(©signl, .{ .name = "copysignl", .linkage = common.linkage, .visibility = common.visibility }); } fn isnan(x: f64) callconv(.c) c_int { @@ -57,3 +63,15 @@ fn nanf(_: [*:0]const c_char) callconv(.c) f32 { fn nanl(_: [*:0]const c_char) callconv(.c) c_longdouble { return std.math.nan(c_longdouble); } + +fn copysignf(x: f32, y: f32) callconv(.c) f32 { + return std.math.copysign(x, y); +} + +fn copysign(x: f64, y: f64) callconv(.c) f64 { + return std.math.copysign(x, y); +} + +fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { + return std.math.copysign(x, y); +} diff --git a/lib/libc/mingw/math/copysign.c b/lib/libc/mingw/math/copysign.c deleted file mode 100644 index c3fe76f0d39b05628dfe8933a2b555d9f4e63544..0000000000000000000000000000000000000000 --- a/lib/libc/mingw/math/copysign.c +++ /dev/null @@ -1,21 +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 - -typedef union U -{ - unsigned int u[2]; - double d; -} U; - -double copysign(double x, double y) -{ - U h,j; - h.d = x; - j.d = y; - h.u[1] = (h.u[1] & 0x7fffffff) | (j.u[1] & 0x80000000); - return h.d; -} diff --git a/lib/libc/mingw/math/copysignf.c b/lib/libc/mingw/math/copysignf.c deleted file mode 100644 index 0fba92bc75989f8c1363388169ab6bd26f62465a..0000000000000000000000000000000000000000 --- a/lib/libc/mingw/math/copysignf.c +++ /dev/null @@ -1,19 +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 - -typedef union ui_f { - float f; - unsigned int ui; -} ui_f; - -float copysignf(float aX, float aY) -{ - ui_f x,y; - x.f=aX; y.f=aY; - x.ui= (x.ui & 0x7fffffff) | (y.ui & 0x80000000); - return x.f; -} diff --git a/lib/libc/mingw/math/x86/copysignl.S b/lib/libc/mingw/math/x86/copysignl.S deleted file mode 100644 index 6f98c7a5d5ad136ecce98daa29331b2b3862bbe5..0000000000000000000000000000000000000000 --- a/lib/libc/mingw/math/x86/copysignl.S +++ /dev/null @@ -1,44 +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. - */ -/* - * Written by J.T. Conklin . - * Changes for long double by Ulrich Drepper - * Public domain. - */ -#include <_mingw_mac.h> - - .file "copysignl.S" - .text -#ifdef __x86_64__ - .align 8 -#else - .align 4 -#endif - - .globl __MINGW_USYMBOL(copysignl) - .def __MINGW_USYMBOL(copysignl); .scl 2; .type 32; .endef -__MINGW_USYMBOL(copysignl): -#if defined(_AMD64_) || defined(__x86_64__) - movq (%rdx), %rax - movq %rax, (%rcx) - movq 8(%rdx), %rax - movq 8(%r8), %rdx - andq $0x7fff, %rax - andq $0x8000, %rdx - orq %rdx, %rax - movq %rax, 8(%rcx) - movq %rcx, %rax - ret -#elif defined(_X86_) || defined(__i386__) - movl 24(%esp),%edx - movl 12(%esp),%eax - andl $0x8000,%edx - andl $0x7fff,%eax - orl %edx,%eax - movl %eax,12(%esp) - fldt 4(%esp) - ret -#endif diff --git a/lib/libc/musl/src/math/copysign.c b/lib/libc/musl/src/math/copysign.c deleted file mode 100644 index b09331b6876e74ebb5c12bdc9a0ee183ee5cc136..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/copysign.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "libm.h" - -double copysign(double x, double y) { - union {double f; uint64_t i;} ux={x}, uy={y}; - ux.i &= -1ULL/2; - ux.i |= uy.i & 1ULL<<63; - return ux.f; -} diff --git a/lib/libc/musl/src/math/copysignf.c b/lib/libc/musl/src/math/copysignf.c deleted file mode 100644 index 0af6ae9b2155da70412f7406e67ab968218d2265..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/copysignf.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -float copysignf(float x, float y) -{ - union {float f; uint32_t i;} ux={x}, uy={y}; - ux.i &= 0x7fffffff; - ux.i |= uy.i & 0x80000000; - return ux.f; -} diff --git a/lib/libc/musl/src/math/copysignl.c b/lib/libc/musl/src/math/copysignl.c deleted file mode 100644 index 9dd933cfa9c55214df9392e9a90dcc83a2dd0c8f..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/copysignl.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double copysignl(long double x, long double y) -{ - return copysign(x, y); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double copysignl(long double x, long double y) -{ - union ldshape ux = {x}, uy = {y}; - ux.i.se &= 0x7fff; - ux.i.se |= uy.i.se & 0x8000; - return ux.f; -} -#endif diff --git a/lib/libc/musl/src/math/riscv32/copysign.c b/lib/libc/musl/src/math/riscv32/copysign.c deleted file mode 100644 index c7854178f053244241cee25ef7a3a122d494fca7..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/riscv32/copysign.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#if __riscv_flen >= 64 - -double copysign(double x, double y) -{ - __asm__ ("fsgnj.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); - return x; -} - -#else - -#include "../copysign.c" - -#endif diff --git a/lib/libc/musl/src/math/riscv32/copysignf.c b/lib/libc/musl/src/math/riscv32/copysignf.c deleted file mode 100644 index a125611ace4422f9ffefbea87432497efa74d268..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/riscv32/copysignf.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#if __riscv_flen >= 32 - -float copysignf(float x, float y) -{ - __asm__ ("fsgnj.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); - return x; -} - -#else - -#include "../copysignf.c" - -#endif diff --git a/lib/libc/musl/src/math/riscv64/copysign.c b/lib/libc/musl/src/math/riscv64/copysign.c deleted file mode 100644 index c7854178f053244241cee25ef7a3a122d494fca7..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/riscv64/copysign.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#if __riscv_flen >= 64 - -double copysign(double x, double y) -{ - __asm__ ("fsgnj.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); - return x; -} - -#else - -#include "../copysign.c" - -#endif diff --git a/lib/libc/musl/src/math/riscv64/copysignf.c b/lib/libc/musl/src/math/riscv64/copysignf.c deleted file mode 100644 index a125611ace4422f9ffefbea87432497efa74d268..0000000000000000000000000000000000000000 --- a/lib/libc/musl/src/math/riscv64/copysignf.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -#if __riscv_flen >= 32 - -float copysignf(float x, float y) -{ - __asm__ ("fsgnj.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); - return x; -} - -#else - -#include "../copysignf.c" - -#endif diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig index a29b424d27663007646f054ea4f7267ac3f3e42b..ded4db0c3e8f2690479f406794de59493ec92eb5 100644 --- a/src/libs/mingw.zig +++ b/src/libs/mingw.zig @@ -957,7 +957,6 @@ const mingw32_x86_src = [_][]const u8{ "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atan2l.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atanhl.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atanl.c", - "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 ++ "cossinl.c", diff --git a/src/libs/musl.zig b/src/libs/musl.zig index 8fc3d608d5032e324543ca86ead989d1fa99fbeb..3393cecbb041159e92a73b7aeb173d3619a1f886 100644 --- a/src/libs/musl.zig +++ b/src/libs/musl.zig @@ -856,9 +856,6 @@ const src_files = [_][]const u8{ "musl/src/math/cbrt.c", "musl/src/math/cbrtf.c", "musl/src/math/cbrtl.c", - "musl/src/math/copysign.c", - "musl/src/math/copysignf.c", - "musl/src/math/copysignl.c", "musl/src/math/__cos.c", "musl/src/math/__cosdf.c", "musl/src/math/cosh.c", @@ -1048,14 +1045,10 @@ const src_files = [_][]const u8{ "musl/src/math/rint.c", "musl/src/math/rintf.c", "musl/src/math/rintl.c", - "musl/src/math/riscv32/copysign.c", - "musl/src/math/riscv32/copysignf.c", "musl/src/math/riscv32/fma.c", "musl/src/math/riscv32/fmaf.c", "musl/src/math/riscv32/sqrt.c", "musl/src/math/riscv32/sqrtf.c", - "musl/src/math/riscv64/copysign.c", - "musl/src/math/riscv64/copysignf.c", "musl/src/math/riscv64/fma.c", "musl/src/math/riscv64/fmaf.c", "musl/src/math/riscv64/sqrt.c", diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig index b523d8f008051441703ca9ae33e3545b06bbd007..1d002e335313b65c4c40c119ecd2a1abb46d49d9 100644 --- a/src/libs/wasi_libc.zig +++ b/src/libs/wasi_libc.zig @@ -710,7 +710,6 @@ const libc_top_half_src_files = [_][]const u8{ "musl/src/math/cbrt.c", "musl/src/math/cbrtf.c", "musl/src/math/cbrtl.c", - "musl/src/math/copysignl.c", "musl/src/math/__cos.c", "musl/src/math/__cosdf.c", "musl/src/math/coshl.c",