Merge pull request #24335 from kada49/common-impl-libc-floor

This commit is contained in:
Alex Rønne Petersen
2025-07-05 03:18:31 +02:00
committed by GitHub
18 changed files with 1 additions and 328 deletions

View File

@@ -1,51 +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 "floorf.S"
.text
.p2align 4,,15
.globl __MINGW_USYMBOL(floorf)
.def __MINGW_USYMBOL(floorf); .scl 2; .type 32; .endef
#ifdef __x86_64__
.seh_proc __MINGW_USYMBOL(floorf)
#endif
__MINGW_USYMBOL(floorf):
#if defined(_AMD64_) || defined(__x86_64__)
subq $40, %rsp
.seh_stackalloc 40
.seh_endprologue
unpcklps %xmm0, %xmm0
cvtps2pd %xmm0, %xmm0
call floor
unpcklpd %xmm0, %xmm0
cvtpd2ps %xmm0, %xmm0
addq $40, %rsp
ret
.seh_endproc
.def __MINGW_USYMBOL(floor); .scl 2; .type 32; .endef
#elif defined(_X86_) || defined(__i386__)
flds 4(%esp)
subl $8,%esp
fstcw 4(%esp) /* store fpu control word */
/* We use here %edx although only the low 1 bits are defined.
But none of the operations should care and they are faster
than the 16 bit operations. */
movl $0x400,%edx /* round towards -oo */
orl 4(%esp),%edx
andl $0xf7ff,%edx
movl %edx,(%esp)
fldcw (%esp) /* load modified control word */
frndint /* round */
fldcw 4(%esp) /* restore original control word */
addl $8,%esp
ret
#endif

View File

@@ -1,63 +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 "floorl.S"
.text
#ifdef __x86_64__
.align 8
#else
.align 4
#endif
.globl __MINGW_USYMBOL(floorl)
.def __MINGW_USYMBOL(floorl); .scl 2; .type 32; .endef
__MINGW_USYMBOL(floorl):
#if defined(_AMD64_) || defined(__x86_64__)
fldt (%rdx)
subq $24,%rsp
fstcw 8(%rsp) /* store fpu control word */
/* We use here %edx although only the low 1 bits are defined.
But none of the operations should care and they are faster
than the 16 bit operations. */
movl $0x400,%edx /* round towards -oo */
orl 8(%rsp),%edx
andl $0xf7ff,%edx
movl %edx,(%rsp)
fldcw (%rsp) /* load modified control word */
frndint /* round */
fldcw 8(%rsp) /* restore original control word */
addq $24,%rsp
movq %rcx,%rax
movq $0,8(%rcx)
fstpt (%rcx)
ret
#elif defined(_X86_) || defined(__i386__)
fldt 4(%esp)
subl $8,%esp
fstcw 4(%esp) /* store fpu control word */
/* We use here %edx although only the low 1 bits are defined.
But none of the operations should care and they are faster
than the 16 bit operations. */
movl $0x400,%edx /* round towards -oo */
orl 4(%esp),%edx
andl $0xf7ff,%edx
movl %edx,(%esp)
fldcw (%esp) /* load modified control word */
frndint /* round */
fldcw 4(%esp) /* restore original control word */
addl $8,%esp
ret
#endif

View File

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

View File

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

View File

@@ -1,31 +0,0 @@
#include "libm.h"
#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
#define EPS DBL_EPSILON
#elif FLT_EVAL_METHOD==2
#define EPS LDBL_EPSILON
#endif
static const double_t toint = 1/EPS;
double floor(double x)
{
union {double f; uint64_t i;} u = {x};
int e = u.i >> 52 & 0x7ff;
double_t y;
if (e >= 0x3ff+52 || x == 0)
return x;
/* y = int(x) - x, where int(x) is an integer neighbor of x */
if (u.i >> 63)
y = x - toint + toint - x;
else
y = x + toint - toint - x;
/* special case because of non-nearest rounding modes */
if (e <= 0x3ff-1) {
FORCE_EVAL(y);
return u.i >> 63 ? -1 : 0;
}
if (y > 0)
return x + y - 1;
return x + y;
}

View File

@@ -1,27 +0,0 @@
#include "libm.h"
float floorf(float x)
{
union {float f; uint32_t i;} u = {x};
int e = (int)(u.i >> 23 & 0xff) - 0x7f;
uint32_t m;
if (e >= 23)
return x;
if (e >= 0) {
m = 0x007fffff >> e;
if ((u.i & m) == 0)
return x;
FORCE_EVAL(x + 0x1p120f);
if (u.i >> 31)
u.i += m;
u.i &= ~m;
} else {
FORCE_EVAL(x + 0x1p120f);
if (u.i >> 31 == 0)
u.i = 0;
else if (u.i << 1)
u.f = -1.0;
}
return u.f;
}

View File

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

View File

@@ -1,20 +1,5 @@
.global floorf
.type floorf,@function
floorf:
flds 4(%esp)
jmp 1f
/* zig patch: removed `floorl` and `floorf` in favor of using zig compiler_rt's implementations */
.global floorl
.type floorl,@function
floorl:
fldt 4(%esp)
jmp 1f
.global floor
.type floor,@function
floor:
fldl 4(%esp)
1: mov $0x7,%al
1: fstcw 4(%esp)
mov 5(%esp),%ah
mov %al,5(%esp)

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 floor(double x)
{
__asm__ ("frim %0, %1" : "=d"(x) : "d"(x));
return x;
}
#else
#include "../floor.c"
#endif

View File

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

View File

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

View File

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

View File

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

View File

@@ -931,7 +931,6 @@ const mingw32_x86_src = [_][]const u8{
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "exp2l.S",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "expl.c",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "expm1l.c",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "floorl.S",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "fmodl.c",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "fucom.c",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "ilogbl.S",
@@ -975,7 +974,6 @@ 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 ++ "floorf.S",
"math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "fmodf.c",
};

View File

@@ -824,8 +824,6 @@ const src_files = [_][]const u8{
"musl/src/malloc/replaced.c",
"musl/src/math/aarch64/ceil.c",
"musl/src/math/aarch64/ceilf.c",
"musl/src/math/aarch64/floor.c",
"musl/src/math/aarch64/floorf.c",
"musl/src/math/aarch64/fma.c",
"musl/src/math/aarch64/fmaf.c",
"musl/src/math/aarch64/fmax.c",
@@ -915,9 +913,6 @@ const src_files = [_][]const u8{
"musl/src/math/fdiml.c",
"musl/src/math/finite.c",
"musl/src/math/finitef.c",
"musl/src/math/floor.c",
"musl/src/math/floorf.c",
"musl/src/math/floorl.c",
"musl/src/math/fma.c",
"musl/src/math/fmaf.c",
"musl/src/math/fmal.c",
@@ -958,8 +953,6 @@ const src_files = [_][]const u8{
"musl/src/math/i386/exp_ld.s",
"musl/src/math/i386/expl.s",
"musl/src/math/i386/expm1l.s",
"musl/src/math/i386/floorf.s",
"musl/src/math/i386/floorl.s",
"musl/src/math/i386/floor.s",
"musl/src/math/i386/fmod.c",
"musl/src/math/i386/fmodf.c",
@@ -1092,8 +1085,6 @@ const src_files = [_][]const u8{
"musl/src/math/pow_data.c",
"musl/src/math/powerpc64/ceil.c",
"musl/src/math/powerpc64/ceilf.c",
"musl/src/math/powerpc64/floor.c",
"musl/src/math/powerpc64/floorf.c",
"musl/src/math/powerpc64/fma.c",
"musl/src/math/powerpc64/fmaf.c",
"musl/src/math/powerpc64/fmax.c",
@@ -1156,9 +1147,6 @@ const src_files = [_][]const u8{
"musl/src/math/s390x/ceil.c",
"musl/src/math/s390x/ceilf.c",
"musl/src/math/s390x/ceill.c",
"musl/src/math/s390x/floor.c",
"musl/src/math/s390x/floorf.c",
"musl/src/math/s390x/floorl.c",
"musl/src/math/s390x/fma.c",
"musl/src/math/s390x/fmaf.c",
"musl/src/math/s390x/nearbyint.c",

View File

@@ -754,7 +754,6 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/math/fdiml.c",
"musl/src/math/finite.c",
"musl/src/math/finitef.c",
"musl/src/math/floorl.c",
"musl/src/math/fma.c",
"musl/src/math/fmaf.c",
"musl/src/math/fmaxl.c",