Commit f707de15a1

David Senoner <seda18@rolmail.net>
2025-08-27 13:40:16
libc: delete superfluous c and assembly ceil implementation
1 parent f6b0d64
lib/libc/mingw/math/x86/ceilf.S
@@ -1,111 +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	"ceilf.S"
-	.text
-	.align 4
-	.globl __MINGW_USYMBOL(ceilf)
-	.def	__MINGW_USYMBOL(ceilf);	.scl	2;	.type	32;	.endef
-#ifdef __x86_64__
-	.seh_proc	__MINGW_USYMBOL(ceilf)
-#endif
-
-__MINGW_USYMBOL(ceilf):
-#if defined(_AMD64_) || defined(__x86_64__)
-        subq    $24, %rsp
-        .seh_stackalloc 24
-        .seh_endprologue
-        movd    %xmm0, 12(%rsp)
-        movl    12(%rsp), %eax
-        movl    %eax, %ecx
-        movl    %eax, %edx
-        sarl    $23, %ecx
-        andl    $255, %ecx
-        subl    $127, %ecx
-        cmpl    $22, %ecx
-        jg      .l4
-        testl   %ecx, %ecx
-        js      .l5
-        movl    $8388607, %r8d
-        sarl    %cl, %r8d
-        testl   %eax, %r8d
-        je      .l3
-        addss   .hugeval(%rip), %xmm0
-        ucomiss .zeroval(%rip), %xmm0
-        jbe     .l2
-        testl   %eax, %eax
-        jle     .l1
-        movl    $8388608, %eax
-        sarl    %cl, %eax
-        addl    %eax, %edx
-.l1:
-        movl    %r8d, %eax
-        notl    %eax
-        andl    %edx, %eax
-.l2:
-        movl    %eax, 8(%rsp)
-        movss   8(%rsp), %xmm0
-.l3:
-        addq    $24, %rsp
-        ret
-        .p2align 4,,10
-.l4:
-        addl    $-128, %ecx
-        jne     .l3
-        addss   %xmm0, %xmm0
-        addq    $24, %rsp
-        ret
-        .p2align 4,,10
-.l5:
-        addss   .hugeval(%rip), %xmm0
-        ucomiss .zeroval(%rip), %xmm0
-        jbe     .islesseqzero
-        testl   %eax, %eax
-        js      .l6
-        movl    $1065353216, %edx
-        cmovne  %edx, %eax
-.islesseqzero:
-        movl    %eax, 8(%rsp)
-        movss   8(%rsp), %xmm0
-        addq    $24, %rsp
-        ret
-        .p2align 4,,10
-.l6:
-        movl    $-2147483648, 8(%rsp)
-        movss   8(%rsp), %xmm0
-        addq    $24, %rsp
-        ret
-        .seh_endproc
-        .section .rdata,"dr"
-        .align 4
-.hugeval:
-        .long   1900671690
-        .align 4
-.zeroval:
-        .long   0
-#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	$0x0800,%edx		/* round towards +oo */
-	orl	4(%esp),%edx
-	andl	$0xfbff,%edx
-	movl	%edx,(%esp)
-	fldcw	(%esp)			/* load modified control word */
-
-	frndint				/* round */
-
-	fldcw	4(%esp)			/* restore original control word */
-
-	addl	$8,%esp
-	ret
-#endif
lib/libc/mingw/math/x86/ceill.S
@@ -1,55 +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	"ceill.S"
-	.text
-#ifdef __x86_64__
-	.align 8
-#else
-	.align 4
-#endif
-	.globl __MINGW_USYMBOL(ceill)
-	.def	__MINGW_USYMBOL(ceill);	.scl	2;	.type	32;	.endef
-__MINGW_USYMBOL(ceill):
-#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	$0x0800,%edx		/* round towards +oo */
-	orl	8(%rsp),%edx
-	andl	$0xfbff,%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)
-	movl	$0x0800,%edx
-	orl	4(%esp),%edx
-	andl	$0xfbff,%edx
-	movl	%edx,(%esp)
-	fldcw	(%esp)
-	frndint
-	fldcw	4(%esp)
-	addl $8,%esp
-	ret
-#endif
lib/libc/musl/src/math/aarch64/ceil.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-double ceil(double x)
-{
-	__asm__ ("frintp %d0, %d1" : "=w"(x) : "w"(x));
-	return x;
-}
lib/libc/musl/src/math/aarch64/ceilf.c
@@ -1,7 +0,0 @@
-#include <math.h>
-
-float ceilf(float x)
-{
-	__asm__ ("frintp %s0, %s1" : "=w"(x) : "w"(x));
-	return x;
-}
lib/libc/musl/src/math/i386/ceil.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/musl/src/math/i386/ceilf.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/musl/src/math/i386/ceill.s
@@ -1,1 +0,0 @@
-# see floor.s
lib/libc/musl/src/math/i386/floor.s
@@ -1,4 +1,4 @@
-/* zig patch: removed `floorl` and `floorf` in favor of using zig compiler_rt's implementations */
+/* 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
@@ -9,27 +9,6 @@
 	fldcw 4(%esp)
 	ret
 
-.global ceil
-.type ceil,@function
-ceil:
-	fldl 4(%esp)
-	mov $0xb,%al
-	jmp 1b
-
-.global ceilf
-.type ceilf,@function
-ceilf:
-	flds 4(%esp)
-	mov $0xb,%al
-	jmp 1b
-
-.global ceill
-.type ceill,@function
-ceill:
-	fldt 4(%esp)
-	mov $0xb,%al
-	jmp 1b
-
 .global trunc
 .type trunc,@function
 trunc:
lib/libc/musl/src/math/powerpc64/ceil.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-double ceil(double x)
-{
-	__asm__ ("frip %0, %1" : "=d"(x) : "d"(x));
-	return x;
-}
-
-#else
-
-#include "../ceil.c"
-
-#endif
lib/libc/musl/src/math/powerpc64/ceilf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#ifdef _ARCH_PWR5X
-
-float ceilf(float x)
-{
-	__asm__ ("frip %0, %1" : "=f"(x) : "f"(x));
-	return x;
-}
-
-#else
-
-#include "../ceilf.c"
-
-#endif
lib/libc/musl/src/math/s390x/ceil.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-double ceil(double x)
-{
-	__asm__ ("fidbra %0, 6, %1, 4" : "=f"(x) : "f"(x));
-	return x;
-}
-
-#else
-
-#include "../ceil.c"
-
-#endif
lib/libc/musl/src/math/s390x/ceilf.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-float ceilf(float x)
-{
-	__asm__ ("fiebra %0, 6, %1, 4" : "=f"(x) : "f"(x));
-	return x;
-}
-
-#else
-
-#include "../ceilf.c"
-
-#endif
lib/libc/musl/src/math/s390x/ceill.c
@@ -1,15 +0,0 @@
-#include <math.h>
-
-#if defined(__HTM__) || __ARCH__ >= 9
-
-long double ceill(long double x)
-{
-	__asm__ ("fixbra %0, 6, %1, 4" : "=f"(x) : "f"(x));
-	return x;
-}
-
-#else
-
-#include "../ceill.c"
-
-#endif
lib/libc/musl/src/math/x32/ceill.s
@@ -1,1 +0,0 @@
-# see floorl.s
lib/libc/musl/src/math/x32/floorl.s
@@ -1,4 +1,4 @@
-/* zig patch: removed `floorl` in favor of using zig compiler_rt's implementations */
+/* zig patch: removed `floorl` and `ceill` in favor of using zig compiler_rt's implementations */
 
 1:	fstcw 8(%esp)
 	mov 9(%esp),%ah
@@ -9,13 +9,6 @@
 	fldcw 8(%esp)
 	ret
 
-.global ceill
-.type ceill,@function
-ceill:
-	fldt 8(%esp)
-	mov $0xb,%al
-	jmp 1b
-
 .global truncl
 .type truncl,@function
 truncl:
lib/libc/musl/src/math/x86_64/ceill.s
@@ -1,1 +0,0 @@
-# see floorl.s
lib/libc/musl/src/math/x86_64/floorl.s
@@ -1,4 +1,4 @@
-/* zig patch: removed `floorl` in favor of using zig compiler_rt's implementations */
+/* zig patch: removed `floorl` and `ceill` in favor of using zig compiler_rt's implementations */
 
 1:	fstcw 8(%rsp)
 	mov 9(%rsp),%ah
@@ -9,13 +9,6 @@
 	fldcw 8(%rsp)
 	ret
 
-.global ceill
-.type ceill,@function
-ceill:
-	fldt 8(%rsp)
-	mov $0xb,%al
-	jmp 1b
-
 .global truncl
 .type truncl,@function
 truncl:
lib/libc/musl/src/math/ceil.c
@@ -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 ceil(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 ? -0.0 : 1;
-	}
-	if (y < 0)
-		return x + y + 1;
-	return x + y;
-}
lib/libc/musl/src/math/ceilf.c
@@ -1,27 +0,0 @@
-#include "libm.h"
-
-float ceilf(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 == 0)
-			u.i += m;
-		u.i &= ~m;
-	} else {
-		FORCE_EVAL(x + 0x1p120f);
-		if (u.i >> 31)
-			u.f = -0.0;
-		else if (u.i << 1)
-			u.f = 1.0;
-	}
-	return u.f;
-}
lib/libc/musl/src/math/ceill.c
@@ -1,34 +0,0 @@
-#include "libm.h"
-
-#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
-long double ceill(long double x)
-{
-	return ceil(x);
-}
-#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
-
-static const long double toint = 1/LDBL_EPSILON;
-
-long double ceill(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 ? -0.0 : 1;
-	}
-	if (y < 0)
-		return x + y + 1;
-	return x + y;
-}
-#endif
src/libs/mingw.zig
@@ -920,7 +920,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 ++ "ceill.S",
     "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",
@@ -970,7 +969,6 @@ const mingw32_x86_32_src = [_][]const u8{
     "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "asinf.c",
     "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 ++ "fmodf.c",
 };
 
src/libs/musl.zig
@@ -831,8 +831,6 @@ const src_files = [_][]const u8{
     "musl/src/malloc/reallocarray.c",
     "musl/src/malloc/realloc.c",
     "musl/src/malloc/replaced.c",
-    "musl/src/math/aarch64/ceil.c",
-    "musl/src/math/aarch64/ceilf.c",
     "musl/src/math/aarch64/fma.c",
     "musl/src/math/aarch64/fmaf.c",
     "musl/src/math/aarch64/fmax.c",
@@ -885,9 +883,6 @@ const src_files = [_][]const u8{
     "musl/src/math/cbrt.c",
     "musl/src/math/cbrtf.c",
     "musl/src/math/cbrtl.c",
-    "musl/src/math/ceil.c",
-    "musl/src/math/ceilf.c",
-    "musl/src/math/ceill.c",
     "musl/src/math/copysign.c",
     "musl/src/math/copysignf.c",
     "musl/src/math/copysignl.c",
@@ -955,9 +950,6 @@ const src_files = [_][]const u8{
     "musl/src/math/i386/atanf.s",
     "musl/src/math/i386/atanl.s",
     "musl/src/math/i386/atan.s",
-    "musl/src/math/i386/ceilf.s",
-    "musl/src/math/i386/ceill.s",
-    "musl/src/math/i386/ceil.s",
     "musl/src/math/i386/exp2l.s",
     "musl/src/math/i386/exp_ld.s",
     "musl/src/math/i386/expl.s",
@@ -1092,8 +1084,6 @@ const src_files = [_][]const u8{
     "musl/src/math/__polevll.c",
     "musl/src/math/pow.c",
     "musl/src/math/pow_data.c",
-    "musl/src/math/powerpc64/ceil.c",
-    "musl/src/math/powerpc64/ceilf.c",
     "musl/src/math/powerpc64/fma.c",
     "musl/src/math/powerpc64/fmaf.c",
     "musl/src/math/powerpc64/fmax.c",
@@ -1153,9 +1143,6 @@ const src_files = [_][]const u8{
     "musl/src/math/round.c",
     "musl/src/math/roundf.c",
     "musl/src/math/roundl.c",
-    "musl/src/math/s390x/ceil.c",
-    "musl/src/math/s390x/ceilf.c",
-    "musl/src/math/s390x/ceill.c",
     "musl/src/math/s390x/fma.c",
     "musl/src/math/s390x/fmaf.c",
     "musl/src/math/s390x/nearbyint.c",
@@ -1216,7 +1203,6 @@ const src_files = [_][]const u8{
     "musl/src/math/x32/asinl.s",
     "musl/src/math/x32/atan2l.s",
     "musl/src/math/x32/atanl.s",
-    "musl/src/math/x32/ceill.s",
     "musl/src/math/x32/exp2l.s",
     "musl/src/math/x32/expl.s",
     "musl/src/math/x32/expm1l.s",
@@ -1245,7 +1231,6 @@ const src_files = [_][]const u8{
     "musl/src/math/x86_64/asinl.s",
     "musl/src/math/x86_64/atan2l.s",
     "musl/src/math/x86_64/atanl.s",
-    "musl/src/math/x86_64/ceill.s",
     "musl/src/math/x86_64/exp2l.s",
     "musl/src/math/x86_64/expl.s",
     "musl/src/math/x86_64/expm1l.s",
src/libs/wasi_libc.zig
@@ -727,7 +727,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/ceill.c",
     "musl/src/math/copysignl.c",
     "musl/src/math/__cos.c",
     "musl/src/math/__cosdf.c",