libc: delete superfluous c and assembly trunc implementations

This commit is contained in:
David Senoner 2025-08-27 21:53:16 +02:00
parent f707de15a1
commit 70e22d79a4
22 changed files with 0 additions and 276 deletions

View file

@ -1,25 +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>
long double
truncl (long double _x)
{
#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
return trunc(_x);
#else
long double retval = 0.0L;
unsigned short saved_cw;
unsigned short tmp_cw;
__asm__ __volatile__ ("fnstcw %0;" : "=m" (saved_cw)); /* save FPU control word */
tmp_cw = saved_cw | 0xc00; /* round towards zero */
__asm__ __volatile__ ("fldcw %0;" : : "m" (tmp_cw));
__asm__ __volatile__ ("frndint;" : "=t" (retval) : "0" (_x)); /* round towards zero */
__asm__ __volatile__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
return retval;
#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
}

View file

@ -1,7 +0,0 @@
#include <math.h>
double trunc(double x)
{
__asm__ ("frintz %d0, %d1" : "=w"(x) : "w"(x));
return x;
}

View file

@ -1,7 +0,0 @@
#include <math.h>
float truncf(float x)
{
__asm__ ("frintz %s0, %s1" : "=w"(x) : "w"(x));
return x;
}

View file

@ -1,31 +0,0 @@
/* zig patch: removed `floorl`, `floorf`, `ceil`, `ceilf` and `ceill` in favor of using zig compiler_rt's implementations */
1: fstcw 4(%esp)
mov 5(%esp),%ah
mov %al,5(%esp)
fldcw 4(%esp)
frndint
mov %ah,5(%esp)
fldcw 4(%esp)
ret
.global trunc
.type trunc,@function
trunc:
fldl 4(%esp)
mov $0xf,%al
jmp 1b
.global truncf
.type truncf,@function
truncf:
flds 4(%esp)
mov $0xf,%al
jmp 1b
.global truncl
.type truncl,@function
truncl:
fldt 4(%esp)
mov $0xf,%al
jmp 1b

View file

@ -1 +0,0 @@
# see floor.s

View file

@ -1 +0,0 @@
# see floor.s

View file

@ -1 +0,0 @@
# see floor.s

View file

@ -1,15 +0,0 @@
#include <math.h>
#ifdef _ARCH_PWR5X
double trunc(double x)
{
__asm__ ("friz %0, %1" : "=d"(x) : "d"(x));
return x;
}
#else
#include "../trunc.c"
#endif

View file

@ -1,15 +0,0 @@
#include <math.h>
#ifdef _ARCH_PWR5X
float truncf(float x)
{
__asm__ ("friz %0, %1" : "=f"(x) : "f"(x));
return x;
}
#else
#include "../truncf.c"
#endif

View file

@ -1,15 +0,0 @@
#include <math.h>
#if defined(__HTM__) || __ARCH__ >= 9
double trunc(double x)
{
__asm__ ("fidbra %0, 5, %1, 4" : "=f"(x) : "f"(x));
return x;
}
#else
#include "../trunc.c"
#endif

View file

@ -1,15 +0,0 @@
#include <math.h>
#if defined(__HTM__) || __ARCH__ >= 9
float truncf(float x)
{
__asm__ ("fiebra %0, 5, %1, 4" : "=f"(x) : "f"(x));
return x;
}
#else
#include "../truncf.c"
#endif

View file

@ -1,15 +0,0 @@
#include <math.h>
#if defined(__HTM__) || __ARCH__ >= 9
long double truncl(long double x)
{
__asm__ ("fixbra %0, 5, %1, 4" : "=f"(x) : "f"(x));
return x;
}
#else
#include "../truncl.c"
#endif

View file

@ -1,19 +0,0 @@
#include "libm.h"
double trunc(double x)
{
union {double f; uint64_t i;} u = {x};
int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12;
uint64_t m;
if (e >= 52 + 12)
return x;
if (e < 12)
e = 1;
m = -1ULL >> e;
if ((u.i & m) == 0)
return x;
FORCE_EVAL(x + 0x1p120f);
u.i &= ~m;
return u.f;
}

View file

@ -1,19 +0,0 @@
#include "libm.h"
float truncf(float x)
{
union {float f; uint32_t i;} u = {x};
int e = (int)(u.i >> 23 & 0xff) - 0x7f + 9;
uint32_t m;
if (e >= 23 + 9)
return x;
if (e < 9)
e = 1;
m = -1U >> e;
if ((u.i & m) == 0)
return x;
FORCE_EVAL(x + 0x1p120f);
u.i &= ~m;
return u.f;
}

View file

@ -1,34 +0,0 @@
#include "libm.h"
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
long double truncl(long double x)
{
return trunc(x);
}
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
static const long double toint = 1/LDBL_EPSILON;
long double truncl(long double x)
{
union ldshape u = {x};
int e = u.i.se & 0x7fff;
int s = u.i.se >> 15;
long double y;
if (e >= 0x3fff+LDBL_MANT_DIG-1)
return x;
if (e <= 0x3fff-1) {
FORCE_EVAL(x + 0x1p120f);
return x*0;
}
/* y = int(|x|) - |x|, where int(|x|) is an integer neighbor of |x| */
if (s)
x = -x;
y = x + toint - toint - x;
if (y > 0)
y -= 1;
x += y;
return s ? -x : x;
}
#endif

View file

@ -1,17 +0,0 @@
/* zig patch: removed `floorl` and `ceill` in favor of using zig compiler_rt's implementations */
1: fstcw 8(%esp)
mov 9(%esp),%ah
mov %al,9(%esp)
fldcw 8(%esp)
frndint
mov %ah,9(%esp)
fldcw 8(%esp)
ret
.global truncl
.type truncl,@function
truncl:
fldt 8(%esp)
mov $0xf,%al
jmp 1b

View file

@ -1 +0,0 @@
# see floorl.s

View file

@ -1,17 +0,0 @@
/* zig patch: removed `floorl` and `ceill` in favor of using zig compiler_rt's implementations */
1: fstcw 8(%rsp)
mov 9(%rsp),%ah
mov %al,9(%rsp)
fldcw 8(%rsp)
frndint
mov %ah,9(%rsp)
fldcw 8(%rsp)
ret
.global truncl
.type truncl,@function
truncl:
fldt 8(%rsp)
mov $0xf,%al
jmp 1b

View file

@ -1 +0,0 @@
# see floorl.s

View file

@ -911,7 +911,6 @@ const mingw32_x86_src = [_][]const u8{
"math" ++ path.sep_str ++ "rintl.c", "math" ++ path.sep_str ++ "rintl.c",
"math" ++ path.sep_str ++ "roundl.c", "math" ++ path.sep_str ++ "roundl.c",
"math" ++ path.sep_str ++ "tgammal.c", "math" ++ path.sep_str ++ "tgammal.c",
"math" ++ path.sep_str ++ "truncl.c",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "_chgsignl.S", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "_chgsignl.S",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acoshl.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acoshl.c",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acosl.c", "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "acosl.c",

View file

@ -853,8 +853,6 @@ const src_files = [_][]const u8{
"musl/src/math/aarch64/roundf.c", "musl/src/math/aarch64/roundf.c",
"musl/src/math/aarch64/sqrt.c", "musl/src/math/aarch64/sqrt.c",
"musl/src/math/aarch64/sqrtf.c", "musl/src/math/aarch64/sqrtf.c",
"musl/src/math/aarch64/trunc.c",
"musl/src/math/aarch64/truncf.c",
"musl/src/math/acos.c", "musl/src/math/acos.c",
"musl/src/math/acosf.c", "musl/src/math/acosf.c",
"musl/src/math/acosh.c", "musl/src/math/acosh.c",
@ -954,7 +952,6 @@ const src_files = [_][]const u8{
"musl/src/math/i386/exp_ld.s", "musl/src/math/i386/exp_ld.s",
"musl/src/math/i386/expl.s", "musl/src/math/i386/expl.s",
"musl/src/math/i386/expm1l.s", "musl/src/math/i386/expm1l.s",
"musl/src/math/i386/floor.s",
"musl/src/math/i386/fmod.c", "musl/src/math/i386/fmod.c",
"musl/src/math/i386/fmodf.c", "musl/src/math/i386/fmodf.c",
"musl/src/math/i386/fmodl.c", "musl/src/math/i386/fmodl.c",
@ -1000,9 +997,6 @@ const src_files = [_][]const u8{
"musl/src/math/i386/sqrt.c", "musl/src/math/i386/sqrt.c",
"musl/src/math/i386/sqrtf.c", "musl/src/math/i386/sqrtf.c",
"musl/src/math/i386/sqrtl.c", "musl/src/math/i386/sqrtl.c",
"musl/src/math/i386/truncf.s",
"musl/src/math/i386/truncl.s",
"musl/src/math/i386/trunc.s",
"musl/src/math/ilogb.c", "musl/src/math/ilogb.c",
"musl/src/math/ilogbf.c", "musl/src/math/ilogbf.c",
"musl/src/math/ilogbl.c", "musl/src/math/ilogbl.c",
@ -1098,8 +1092,6 @@ const src_files = [_][]const u8{
"musl/src/math/powerpc64/roundf.c", "musl/src/math/powerpc64/roundf.c",
"musl/src/math/powerpc64/sqrt.c", "musl/src/math/powerpc64/sqrt.c",
"musl/src/math/powerpc64/sqrtf.c", "musl/src/math/powerpc64/sqrtf.c",
"musl/src/math/powerpc64/trunc.c",
"musl/src/math/powerpc64/truncf.c",
"musl/src/math/powerpc/fma.c", "musl/src/math/powerpc/fma.c",
"musl/src/math/powerpc/fmaf.c", "musl/src/math/powerpc/fmaf.c",
"musl/src/math/powerpc/sqrt.c", "musl/src/math/powerpc/sqrt.c",
@ -1157,9 +1149,6 @@ const src_files = [_][]const u8{
"musl/src/math/s390x/sqrt.c", "musl/src/math/s390x/sqrt.c",
"musl/src/math/s390x/sqrtf.c", "musl/src/math/s390x/sqrtf.c",
"musl/src/math/s390x/sqrtl.c", "musl/src/math/s390x/sqrtl.c",
"musl/src/math/s390x/trunc.c",
"musl/src/math/s390x/truncf.c",
"musl/src/math/s390x/truncl.c",
"musl/src/math/scalb.c", "musl/src/math/scalb.c",
"musl/src/math/scalbf.c", "musl/src/math/scalbf.c",
"musl/src/math/scalbln.c", "musl/src/math/scalbln.c",
@ -1196,9 +1185,6 @@ const src_files = [_][]const u8{
"musl/src/math/tgamma.c", "musl/src/math/tgamma.c",
"musl/src/math/tgammaf.c", "musl/src/math/tgammaf.c",
"musl/src/math/tgammal.c", "musl/src/math/tgammal.c",
"musl/src/math/trunc.c",
"musl/src/math/truncf.c",
"musl/src/math/truncl.c",
"musl/src/math/x32/acosl.s", "musl/src/math/x32/acosl.s",
"musl/src/math/x32/asinl.s", "musl/src/math/x32/asinl.s",
"musl/src/math/x32/atan2l.s", "musl/src/math/x32/atan2l.s",
@ -1206,7 +1192,6 @@ const src_files = [_][]const u8{
"musl/src/math/x32/exp2l.s", "musl/src/math/x32/exp2l.s",
"musl/src/math/x32/expl.s", "musl/src/math/x32/expl.s",
"musl/src/math/x32/expm1l.s", "musl/src/math/x32/expm1l.s",
"musl/src/math/x32/floorl.s",
"musl/src/math/x32/fma.c", "musl/src/math/x32/fma.c",
"musl/src/math/x32/fmaf.c", "musl/src/math/x32/fmaf.c",
"musl/src/math/x32/fmodl.s", "musl/src/math/x32/fmodl.s",
@ -1226,7 +1211,6 @@ const src_files = [_][]const u8{
"musl/src/math/x32/sqrtf.s", "musl/src/math/x32/sqrtf.s",
"musl/src/math/x32/sqrtl.s", "musl/src/math/x32/sqrtl.s",
"musl/src/math/x32/sqrt.s", "musl/src/math/x32/sqrt.s",
"musl/src/math/x32/truncl.s",
"musl/src/math/x86_64/acosl.s", "musl/src/math/x86_64/acosl.s",
"musl/src/math/x86_64/asinl.s", "musl/src/math/x86_64/asinl.s",
"musl/src/math/x86_64/atan2l.s", "musl/src/math/x86_64/atan2l.s",
@ -1234,7 +1218,6 @@ const src_files = [_][]const u8{
"musl/src/math/x86_64/exp2l.s", "musl/src/math/x86_64/exp2l.s",
"musl/src/math/x86_64/expl.s", "musl/src/math/x86_64/expl.s",
"musl/src/math/x86_64/expm1l.s", "musl/src/math/x86_64/expm1l.s",
"musl/src/math/x86_64/floorl.s",
"musl/src/math/x86_64/fma.c", "musl/src/math/x86_64/fma.c",
"musl/src/math/x86_64/fmaf.c", "musl/src/math/x86_64/fmaf.c",
"musl/src/math/x86_64/fmodl.c", "musl/src/math/x86_64/fmodl.c",
@ -1255,7 +1238,6 @@ const src_files = [_][]const u8{
"musl/src/math/x86_64/sqrt.c", "musl/src/math/x86_64/sqrt.c",
"musl/src/math/x86_64/sqrtf.c", "musl/src/math/x86_64/sqrtf.c",
"musl/src/math/x86_64/sqrtl.c", "musl/src/math/x86_64/sqrtl.c",
"musl/src/math/x86_64/truncl.s",
"musl/src/misc/a64l.c", "musl/src/misc/a64l.c",
"musl/src/misc/basename.c", "musl/src/misc/basename.c",
"musl/src/misc/dirname.c", "musl/src/misc/dirname.c",

View file

@ -886,7 +886,6 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/math/tgamma.c", "musl/src/math/tgamma.c",
"musl/src/math/tgammaf.c", "musl/src/math/tgammaf.c",
"musl/src/math/tgammal.c", "musl/src/math/tgammal.c",
"musl/src/math/truncl.c",
"musl/src/misc/a64l.c", "musl/src/misc/a64l.c",
"musl/src/misc/basename.c", "musl/src/misc/basename.c",
"musl/src/misc/dirname.c", "musl/src/misc/dirname.c",