aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Senoner <seda18@rolmail.net>2025-08-26 14:16:55 +0200
committerAlex Rønne Petersen <alex@alexrp.com>2025-08-27 03:58:32 +0200
commit9399fcddce0bcd8e987b053f3946aa1b0ff2ef0a (patch)
treed72180f3ea1097a78cb52fc6567a1d7762efee41 /lib
parentaae5560712fb67cea2b1405c4e2b03e9be236678 (diff)
downloadzig-9399fcddce0bcd8e987b053f3946aa1b0ff2ef0a.tar.gz
zig-9399fcddce0bcd8e987b053f3946aa1b0ff2ef0a.zip
libc: use zig isnan and derivates for mingw
Diffstat (limited to 'lib')
-rw-r--r--lib/c.zig1
-rw-r--r--lib/c/math.zig26
-rw-r--r--lib/libc/mingw/math/isnan.c31
-rw-r--r--lib/libc/mingw/math/isnanf.c27
-rw-r--r--lib/libc/mingw/math/isnanl.c32
5 files changed, 27 insertions, 90 deletions
diff --git a/lib/c.zig b/lib/c.zig
index dec072e409..d59ef950f4 100644
--- a/lib/c.zig
+++ b/lib/c.zig
@@ -16,6 +16,7 @@ else
comptime {
_ = @import("c/inttypes.zig");
_ = @import("c/stdlib.zig");
+ _ = @import("c/math.zig");
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
// Files specific to musl and wasi-libc.
diff --git a/lib/c/math.zig b/lib/c/math.zig
new file mode 100644
index 0000000000..161e400e6d
--- /dev/null
+++ b/lib/c/math.zig
@@ -0,0 +1,26 @@
+const std = @import("std");
+const common = @import("common.zig");
+const builtin = @import("builtin");
+
+comptime {
+ if (builtin.target.isMinGW()) {
+ @export(&isnan, .{ .name = "isnan", .linkage = common.linkage, .visibility = common.visibility });
+ @export(&isnan, .{ .name = "__isnan", .linkage = common.linkage, .visibility = common.visibility });
+ @export(&isnanf, .{ .name = "isnanf", .linkage = common.linkage, .visibility = common.visibility });
+ @export(&isnanf, .{ .name = "__isnanf", .linkage = common.linkage, .visibility = common.visibility });
+ @export(&isnanl, .{ .name = "isnanl", .linkage = common.linkage, .visibility = common.visibility });
+ @export(&isnanl, .{ .name = "__isnanl", .linkage = common.linkage, .visibility = common.visibility });
+ }
+}
+
+fn isnan(x: f64) callconv(.c) c_int {
+ return if (std.math.isNan(x)) 1 else 0;
+}
+
+fn isnanf(x: f32) callconv(.c) c_int {
+ return if (std.math.isNan(x)) 1 else 0;
+}
+
+fn isnanl(x: c_longdouble) callconv(.c) c_int {
+ return if (std.math.isNan(x)) 1 else 0;
+}
diff --git a/lib/libc/mingw/math/isnan.c b/lib/libc/mingw/math/isnan.c
deleted file mode 100644
index 57423c2930..0000000000
--- a/lib/libc/mingw/math/isnan.c
+++ /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 <math.h>
-
-int
-__isnan (double _x)
-{
-#if defined(__x86_64__) || defined(_AMD64_) || defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
- __mingw_dbl_type_t hlp;
- int l, h;
-
- hlp.x = _x;
- l = hlp.lh.low;
- h = hlp.lh.high & 0x7fffffff;
- h |= (unsigned int) (l | -l) >> 31;
- h = 0x7ff00000 - h;
- return (int) ((unsigned int) h) >> 31;
-#elif defined(__i386__) || defined(_X86_)
- unsigned short _sw;
- __asm__ __volatile__ ("fxam;"
- "fstsw %%ax": "=a" (_sw) : "t" (_x));
- return (_sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
- == FP_NAN;
-#endif
-}
-
-#undef isnan
-int __attribute__ ((alias ("__isnan"))) isnan (double);
diff --git a/lib/libc/mingw/math/isnanf.c b/lib/libc/mingw/math/isnanf.c
deleted file mode 100644
index 0c8e5041e7..0000000000
--- a/lib/libc/mingw/math/isnanf.c
+++ /dev/null
@@ -1,27 +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 <math.h>
-int
-__isnanf (float _x)
-{
-#if defined(__x86_64__) || defined(_AMD64_) || defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
- __mingw_flt_type_t hlp;
- int i;
-
- hlp.x = _x;
- i = hlp.val & 0x7fffffff;
- i = 0x7f800000 - i;
- return (int) (((unsigned int) i) >> 31);
-#elif defined(__i386__) || defined(_X86_)
- unsigned short _sw;
- __asm__ __volatile__ ("fxam;"
- "fstsw %%ax": "=a" (_sw) : "t" (_x) );
- return (_sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
- == FP_NAN;
-#endif
-}
-
-int __attribute__ ((alias ("__isnanf"))) isnanf (float);
diff --git a/lib/libc/mingw/math/isnanl.c b/lib/libc/mingw/math/isnanl.c
deleted file mode 100644
index fdc2529a9f..0000000000
--- a/lib/libc/mingw/math/isnanl.c
+++ /dev/null
@@ -1,32 +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 <math.h>
-
-int
-__isnanl (long double _x)
-{
-#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
- return __isnan(_x);
-#elif defined(__x86_64__) || defined(_AMD64_)
- __mingw_ldbl_type_t ld;
- int xx, signexp;
-
- ld.x = _x;
- signexp = (ld.lh.sign_exponent & 0x7fff) << 1;
- xx = (int) (ld.lh.low | (ld.lh.high & 0x7fffffffu)); /* explicit */
- signexp |= (unsigned int) (xx | (-xx)) >> 31;
- signexp = 0xfffe - signexp;
- return (int) ((unsigned int) signexp) >> 16;
-#elif defined(__i386__) || defined(_X86_)
- unsigned short _sw;
- __asm__ __volatile__ ("fxam;"
- "fstsw %%ax": "=a" (_sw) : "t" (_x));
- return (_sw & (FP_NAN | FP_NORMAL | FP_INFINITE | FP_ZERO | FP_SUBNORMAL))
- == FP_NAN;
-#endif
-}
-
-int __attribute__ ((alias ("__isnanl"))) isnanl (long double);