authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-07-05 03:18:31+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-07-05 03:18:31+02:00
logfc993945a92a1bf2577354359897071ec52f4b90
tree083c07bd48a4234c3785cc9ee796b3057c0a83c7
parentbe20f97eb97d4712bfd9be85ed2e41acbb7718de
parentb78751051f4b386899fb82054fc008f9dad73432
signaturebadge-check Signed by PGP key B5690EEEBB952194

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


18 files changed, 1 insertions(+), 328 deletions(-)

lib/libc/mingw/math/x86/floorf.S deleted-51
......@@ -1,51 +0,0 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6 #include <_mingw_mac.h>
7
8 .file "floorf.S"
9 .text
10 .p2align 4,,15
11 .globl __MINGW_USYMBOL(floorf)
12 .def __MINGW_USYMBOL(floorf); .scl 2; .type 32; .endef
13#ifdef __x86_64__
14 .seh_proc __MINGW_USYMBOL(floorf)
15#endif
16__MINGW_USYMBOL(floorf):
17#if defined(_AMD64_) || defined(__x86_64__)
18 subq $40, %rsp
19 .seh_stackalloc 40
20 .seh_endprologue
21 unpcklps %xmm0, %xmm0
22 cvtps2pd %xmm0, %xmm0
23 call floor
24 unpcklpd %xmm0, %xmm0
25 cvtpd2ps %xmm0, %xmm0
26 addq $40, %rsp
27 ret
28 .seh_endproc
29 .def __MINGW_USYMBOL(floor); .scl 2; .type 32; .endef
30#elif defined(_X86_) || defined(__i386__)
31 flds 4(%esp)
32 subl $8,%esp
33
34 fstcw 4(%esp) /* store fpu control word */
35
36 /* We use here %edx although only the low 1 bits are defined.
37 But none of the operations should care and they are faster
38 than the 16 bit operations. */
39 movl $0x400,%edx /* round towards -oo */
40 orl 4(%esp),%edx
41 andl $0xf7ff,%edx
42 movl %edx,(%esp)
43 fldcw (%esp) /* load modified control word */
44
45 frndint /* round */
46
47 fldcw 4(%esp) /* restore original control word */
48
49 addl $8,%esp
50 ret
51#endif
lib/libc/mingw/math/x86/floorl.S deleted-63
......@@ -1,63 +0,0 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6#include <_mingw_mac.h>
7
8 .file "floorl.S"
9 .text
10#ifdef __x86_64__
11 .align 8
12#else
13 .align 4
14#endif
15 .globl __MINGW_USYMBOL(floorl)
16 .def __MINGW_USYMBOL(floorl); .scl 2; .type 32; .endef
17__MINGW_USYMBOL(floorl):
18#if defined(_AMD64_) || defined(__x86_64__)
19 fldt (%rdx)
20 subq $24,%rsp
21
22 fstcw 8(%rsp) /* store fpu control word */
23
24 /* We use here %edx although only the low 1 bits are defined.
25 But none of the operations should care and they are faster
26 than the 16 bit operations. */
27 movl $0x400,%edx /* round towards -oo */
28 orl 8(%rsp),%edx
29 andl $0xf7ff,%edx
30 movl %edx,(%rsp)
31 fldcw (%rsp) /* load modified control word */
32
33 frndint /* round */
34
35 fldcw 8(%rsp) /* restore original control word */
36
37 addq $24,%rsp
38 movq %rcx,%rax
39 movq $0,8(%rcx)
40 fstpt (%rcx)
41 ret
42#elif defined(_X86_) || defined(__i386__)
43 fldt 4(%esp)
44 subl $8,%esp
45
46 fstcw 4(%esp) /* store fpu control word */
47
48 /* We use here %edx although only the low 1 bits are defined.
49 But none of the operations should care and they are faster
50 than the 16 bit operations. */
51 movl $0x400,%edx /* round towards -oo */
52 orl 4(%esp),%edx
53 andl $0xf7ff,%edx
54 movl %edx,(%esp)
55 fldcw (%esp) /* load modified control word */
56
57 frndint /* round */
58
59 fldcw 4(%esp) /* restore original control word */
60
61 addl $8,%esp
62 ret
63#endif
lib/libc/musl/src/math/aarch64/floor.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3double floor(double x)
4{
5 __asm__ ("frintm %d0, %d1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/musl/src/math/aarch64/floorf.c deleted-7
......@@ -1,7 +0,0 @@
1#include <math.h>
2
3float floorf(float x)
4{
5 __asm__ ("frintm %s0, %s1" : "=w"(x) : "w"(x));
6 return x;
7}
lib/libc/musl/src/math/floor.c deleted-31
......@@ -1,31 +0,0 @@
1#include "libm.h"
2
3#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
4#define EPS DBL_EPSILON
5#elif FLT_EVAL_METHOD==2
6#define EPS LDBL_EPSILON
7#endif
8static const double_t toint = 1/EPS;
9
10double floor(double x)
11{
12 union {double f; uint64_t i;} u = {x};
13 int e = u.i >> 52 & 0x7ff;
14 double_t y;
15
16 if (e >= 0x3ff+52 || x == 0)
17 return x;
18 /* y = int(x) - x, where int(x) is an integer neighbor of x */
19 if (u.i >> 63)
20 y = x - toint + toint - x;
21 else
22 y = x + toint - toint - x;
23 /* special case because of non-nearest rounding modes */
24 if (e <= 0x3ff-1) {
25 FORCE_EVAL(y);
26 return u.i >> 63 ? -1 : 0;
27 }
28 if (y > 0)
29 return x + y - 1;
30 return x + y;
31}
lib/libc/musl/src/math/floorf.c deleted-27
......@@ -1,27 +0,0 @@
1#include "libm.h"
2
3float floorf(float x)
4{
5 union {float f; uint32_t i;} u = {x};
6 int e = (int)(u.i >> 23 & 0xff) - 0x7f;
7 uint32_t m;
8
9 if (e >= 23)
10 return x;
11 if (e >= 0) {
12 m = 0x007fffff >> e;
13 if ((u.i & m) == 0)
14 return x;
15 FORCE_EVAL(x + 0x1p120f);
16 if (u.i >> 31)
17 u.i += m;
18 u.i &= ~m;
19 } else {
20 FORCE_EVAL(x + 0x1p120f);
21 if (u.i >> 31 == 0)
22 u.i = 0;
23 else if (u.i << 1)
24 u.f = -1.0;
25 }
26 return u.f;
27}
lib/libc/musl/src/math/floorl.c deleted-34
......@@ -1,34 +0,0 @@
1#include "libm.h"
2
3#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
4long double floorl(long double x)
5{
6 return floor(x);
7}
8#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
9
10static const long double toint = 1/LDBL_EPSILON;
11
12long double floorl(long double x)
13{
14 union ldshape u = {x};
15 int e = u.i.se & 0x7fff;
16 long double y;
17
18 if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0)
19 return x;
20 /* y = int(x) - x, where int(x) is an integer neighbor of x */
21 if (u.i.se >> 15)
22 y = x - toint + toint - x;
23 else
24 y = x + toint - toint - x;
25 /* special case because of non-nearest rounding modes */
26 if (e <= 0x3fff-1) {
27 FORCE_EVAL(y);
28 return u.i.se >> 15 ? -1 : 0;
29 }
30 if (y > 0)
31 return x + y - 1;
32 return x + y;
33}
34#endif
lib/libc/musl/src/math/i386/floor.s+1-16
......@@ -1,20 +1,5 @@
1.global floorf
2.type floorf,@function
3floorf:
4 flds 4(%esp)
5 jmp 1f
6
7.global floorl
8.type floorl,@function
9floorl:
10 fldt 4(%esp)
11 jmp 1f
1/* zig patch: removed `floorl` and `floorf` in favor of using zig compiler_rt's implementations */
122
13.global floor
14.type floor,@function
15floor:
16 fldl 4(%esp)
171: mov $0x7,%al
1831: fstcw 4(%esp)
194 mov 5(%esp),%ah
205 mov %al,5(%esp)
lib/libc/musl/src/math/i386/floorf.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/musl/src/math/i386/floorl.s deleted-1
......@@ -1 +0,0 @@
1# see floor.s
lib/libc/musl/src/math/powerpc64/floor.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5double floor(double x)
6{
7 __asm__ ("frim %0, %1" : "=d"(x) : "d"(x));
8 return x;
9}
10
11#else
12
13#include "../floor.c"
14
15#endif
lib/libc/musl/src/math/powerpc64/floorf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#ifdef _ARCH_PWR5X
4
5float floorf(float x)
6{
7 __asm__ ("frim %0, %1" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../floorf.c"
14
15#endif
lib/libc/musl/src/math/s390x/floor.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5double floor(double x)
6{
7 __asm__ ("fidbra %0, 7, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../floor.c"
14
15#endif
lib/libc/musl/src/math/s390x/floorf.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5float floorf(float x)
6{
7 __asm__ ("fiebra %0, 7, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../floorf.c"
14
15#endif
lib/libc/musl/src/math/s390x/floorl.c deleted-15
......@@ -1,15 +0,0 @@
1#include <math.h>
2
3#if defined(__HTM__) || __ARCH__ >= 9
4
5long double floorl(long double x)
6{
7 __asm__ ("fixbra %0, 7, %1, 4" : "=f"(x) : "f"(x));
8 return x;
9}
10
11#else
12
13#include "../floorl.c"
14
15#endif
src/libs/mingw.zig-2
......@@ -931,7 +931,6 @@ const mingw32_x86_src = [_][]const u8{
931931 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "exp2l.S",
932932 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "expl.c",
933933 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "expm1l.c",
934 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "floorl.S",
935934 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "fmodl.c",
936935 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "fucom.c",
937936 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "ilogbl.S",
......@@ -975,7 +974,6 @@ const mingw32_x86_32_src = [_][]const u8{
975974 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atan2f.c",
976975 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "atanf.c",
977976 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "ceilf.S",
978 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "floorf.S",
979977 "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "fmodf.c",
980978};
981979
src/libs/musl.zig-12
......@@ -824,8 +824,6 @@ const src_files = [_][]const u8{
824824 "musl/src/malloc/replaced.c",
825825 "musl/src/math/aarch64/ceil.c",
826826 "musl/src/math/aarch64/ceilf.c",
827 "musl/src/math/aarch64/floor.c",
828 "musl/src/math/aarch64/floorf.c",
829827 "musl/src/math/aarch64/fma.c",
830828 "musl/src/math/aarch64/fmaf.c",
831829 "musl/src/math/aarch64/fmax.c",
......@@ -915,9 +913,6 @@ const src_files = [_][]const u8{
915913 "musl/src/math/fdiml.c",
916914 "musl/src/math/finite.c",
917915 "musl/src/math/finitef.c",
918 "musl/src/math/floor.c",
919 "musl/src/math/floorf.c",
920 "musl/src/math/floorl.c",
921916 "musl/src/math/fma.c",
922917 "musl/src/math/fmaf.c",
923918 "musl/src/math/fmal.c",
......@@ -958,8 +953,6 @@ const src_files = [_][]const u8{
958953 "musl/src/math/i386/exp_ld.s",
959954 "musl/src/math/i386/expl.s",
960955 "musl/src/math/i386/expm1l.s",
961 "musl/src/math/i386/floorf.s",
962 "musl/src/math/i386/floorl.s",
963956 "musl/src/math/i386/floor.s",
964957 "musl/src/math/i386/fmod.c",
965958 "musl/src/math/i386/fmodf.c",
......@@ -1092,8 +1085,6 @@ const src_files = [_][]const u8{
10921085 "musl/src/math/pow_data.c",
10931086 "musl/src/math/powerpc64/ceil.c",
10941087 "musl/src/math/powerpc64/ceilf.c",
1095 "musl/src/math/powerpc64/floor.c",
1096 "musl/src/math/powerpc64/floorf.c",
10971088 "musl/src/math/powerpc64/fma.c",
10981089 "musl/src/math/powerpc64/fmaf.c",
10991090 "musl/src/math/powerpc64/fmax.c",
......@@ -1156,9 +1147,6 @@ const src_files = [_][]const u8{
11561147 "musl/src/math/s390x/ceil.c",
11571148 "musl/src/math/s390x/ceilf.c",
11581149 "musl/src/math/s390x/ceill.c",
1159 "musl/src/math/s390x/floor.c",
1160 "musl/src/math/s390x/floorf.c",
1161 "musl/src/math/s390x/floorl.c",
11621150 "musl/src/math/s390x/fma.c",
11631151 "musl/src/math/s390x/fmaf.c",
11641152 "musl/src/math/s390x/nearbyint.c",
src/libs/wasi_libc.zig-1
......@@ -754,7 +754,6 @@ const libc_top_half_src_files = [_][]const u8{
754754 "musl/src/math/fdiml.c",
755755 "musl/src/math/finite.c",
756756 "musl/src/math/finitef.c",
757 "musl/src/math/floorl.c",
758757 "musl/src/math/fma.c",
759758 "musl/src/math/fmaf.c",
760759 "musl/src/math/fmaxl.c",