From 813ae89208ae39181ecfbd6b76a0e8fd9a38e97b Mon Sep 17 00:00:00 2001 From: rpkak Date: Thu, 8 Jan 2026 08:19:53 +0100 Subject: [PATCH] libc -> libzigc: copysign --- lib/c/math.zig | 18 +++++++++ lib/libc/mingw/math/copysign.c | 21 ----------- lib/libc/mingw/math/copysignf.c | 19 ---------- lib/libc/mingw/math/x86/copysignl.S | 44 ---------------------- lib/libc/musl/src/math/copysign.c | 8 ---- lib/libc/musl/src/math/copysignf.c | 10 ----- lib/libc/musl/src/math/copysignl.c | 16 -------- lib/libc/musl/src/math/riscv32/copysign.c | 15 -------- lib/libc/musl/src/math/riscv32/copysignf.c | 15 -------- lib/libc/musl/src/math/riscv64/copysign.c | 15 -------- lib/libc/musl/src/math/riscv64/copysignf.c | 15 -------- src/libs/mingw.zig | 1 - src/libs/musl.zig | 7 ---- src/libs/wasi_libc.zig | 1 - 14 files changed, 18 insertions(+), 187 deletions(-) delete mode 100644 lib/libc/mingw/math/copysign.c delete mode 100644 lib/libc/mingw/math/copysignf.c delete mode 100644 lib/libc/mingw/math/x86/copysignl.S delete mode 100644 lib/libc/musl/src/math/copysign.c delete mode 100644 lib/libc/musl/src/math/copysignf.c delete mode 100644 lib/libc/musl/src/math/copysignl.c delete mode 100644 lib/libc/musl/src/math/riscv32/copysign.c delete mode 100644 lib/libc/musl/src/math/riscv32/copysignf.c delete mode 100644 lib/libc/musl/src/math/riscv64/copysign.c delete mode 100644 lib/libc/musl/src/math/riscv64/copysignf.c diff --git a/lib/c/math.zig b/lib/c/math.zig index 8282b1ff0a..3e4aa662d0 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 c3fe76f0d3..0000000000 --- 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 0fba92bc75..0000000000 --- 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 6f98c7a5d5..0000000000 --- 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 b09331b687..0000000000 --- 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 0af6ae9b21..0000000000 --- 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 9dd933cfa9..0000000000 --- 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 c7854178f0..0000000000 --- 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 a125611ace..0000000000 --- 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 c7854178f0..0000000000 --- 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 a125611ace..0000000000 --- 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 a29b424d27..ded4db0c3e 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 8fc3d608d5..3393cecbb0 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 b523d8f008..1d002e3353 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",