authorgravatar for mercenary@noreply.codeberg.orgmercenary <mercenary@noreply.codeberg.org> 2025-12-29 15:55:18+01:00
committergravatar for mercenary@noreply.codeberg.orgmercenary <mercenary@noreply.codeberg.org> 2025-12-29 15:55:18+01:00
log1c05823ff89afc564252fecbf9f91ff5f19fea80
tree666e4af3a8583d803f5c0a0358686459f1265192
parent5e4aefd2a6dc3bd1db9bf9235b30217c52b0ff80

libc: remove `exp` and `expf`

These symbols are already provided by compiler_rt

6 files changed, 0 insertions(+), 230 deletions(-)

lib/libc/mingw/math/expf.c deleted-11
......@@ -1,11 +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 <math.h>
7
8float expf (float x)
9{
10 return (float) exp (x);
11}
lib/libc/musl/src/math/exp.c deleted-134
......@@ -1,134 +0,0 @@
1/*
2 * Double-precision e^x function.
3 *
4 * Copyright (c) 2018, Arm Limited.
5 * SPDX-License-Identifier: MIT
6 */
7
8#include <math.h>
9#include <stdint.h>
10#include "libm.h"
11#include "exp_data.h"
12
13#define N (1 << EXP_TABLE_BITS)
14#define InvLn2N __exp_data.invln2N
15#define NegLn2hiN __exp_data.negln2hiN
16#define NegLn2loN __exp_data.negln2loN
17#define Shift __exp_data.shift
18#define T __exp_data.tab
19#define C2 __exp_data.poly[5 - EXP_POLY_ORDER]
20#define C3 __exp_data.poly[6 - EXP_POLY_ORDER]
21#define C4 __exp_data.poly[7 - EXP_POLY_ORDER]
22#define C5 __exp_data.poly[8 - EXP_POLY_ORDER]
23
24/* Handle cases that may overflow or underflow when computing the result that
25 is scale*(1+TMP) without intermediate rounding. The bit representation of
26 scale is in SBITS, however it has a computed exponent that may have
27 overflown into the sign bit so that needs to be adjusted before using it as
28 a double. (int32_t)KI is the k used in the argument reduction and exponent
29 adjustment of scale, positive k here means the result may overflow and
30 negative k means the result may underflow. */
31static inline double specialcase(double_t tmp, uint64_t sbits, uint64_t ki)
32{
33 double_t scale, y;
34
35 if ((ki & 0x80000000) == 0) {
36 /* k > 0, the exponent of scale might have overflowed by <= 460. */
37 sbits -= 1009ull << 52;
38 scale = asdouble(sbits);
39 y = 0x1p1009 * (scale + scale * tmp);
40 return eval_as_double(y);
41 }
42 /* k < 0, need special care in the subnormal range. */
43 sbits += 1022ull << 52;
44 scale = asdouble(sbits);
45 y = scale + scale * tmp;
46 if (y < 1.0) {
47 /* Round y to the right precision before scaling it into the subnormal
48 range to avoid double rounding that can cause 0.5+E/2 ulp error where
49 E is the worst-case ulp error outside the subnormal range. So this
50 is only useful if the goal is better than 1 ulp worst-case error. */
51 double_t hi, lo;
52 lo = scale - y + scale * tmp;
53 hi = 1.0 + y;
54 lo = 1.0 - hi + y + lo;
55 y = eval_as_double(hi + lo) - 1.0;
56 /* Avoid -0.0 with downward rounding. */
57 if (WANT_ROUNDING && y == 0.0)
58 y = 0.0;
59 /* The underflow exception needs to be signaled explicitly. */
60 fp_force_eval(fp_barrier(0x1p-1022) * 0x1p-1022);
61 }
62 y = 0x1p-1022 * y;
63 return eval_as_double(y);
64}
65
66/* Top 12 bits of a double (sign and exponent bits). */
67static inline uint32_t top12(double x)
68{
69 return asuint64(x) >> 52;
70}
71
72double exp(double x)
73{
74 uint32_t abstop;
75 uint64_t ki, idx, top, sbits;
76 double_t kd, z, r, r2, scale, tail, tmp;
77
78 abstop = top12(x) & 0x7ff;
79 if (predict_false(abstop - top12(0x1p-54) >= top12(512.0) - top12(0x1p-54))) {
80 if (abstop - top12(0x1p-54) >= 0x80000000)
81 /* Avoid spurious underflow for tiny x. */
82 /* Note: 0 is common input. */
83 return WANT_ROUNDING ? 1.0 + x : 1.0;
84 if (abstop >= top12(1024.0)) {
85 if (asuint64(x) == asuint64(-INFINITY))
86 return 0.0;
87 if (abstop >= top12(INFINITY))
88 return 1.0 + x;
89 if (asuint64(x) >> 63)
90 return __math_uflow(0);
91 else
92 return __math_oflow(0);
93 }
94 /* Large x is special cased below. */
95 abstop = 0;
96 }
97
98 /* exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)]. */
99 /* x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N]. */
100 z = InvLn2N * x;
101#if TOINT_INTRINSICS
102 kd = roundtoint(z);
103 ki = converttoint(z);
104#elif EXP_USE_TOINT_NARROW
105 /* z - kd is in [-0.5-2^-16, 0.5] in all rounding modes. */
106 kd = eval_as_double(z + Shift);
107 ki = asuint64(kd) >> 16;
108 kd = (double_t)(int32_t)ki;
109#else
110 /* z - kd is in [-1, 1] in non-nearest rounding modes. */
111 kd = eval_as_double(z + Shift);
112 ki = asuint64(kd);
113 kd -= Shift;
114#endif
115 r = x + kd * NegLn2hiN + kd * NegLn2loN;
116 /* 2^(k/N) ~= scale * (1 + tail). */
117 idx = 2 * (ki % N);
118 top = ki << (52 - EXP_TABLE_BITS);
119 tail = asdouble(T[idx]);
120 /* This is only a valid scale when -1023*N < k < 1024*N. */
121 sbits = T[idx + 1] + top;
122 /* exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1). */
123 /* Evaluation is optimized assuming superscalar pipelined execution. */
124 r2 = r * r;
125 /* Without fma the worst case error is 0.25/N ulp larger. */
126 /* Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp. */
127 tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);
128 if (predict_false(abstop == 0))
129 return specialcase(tmp, sbits, ki);
130 scale = asdouble(sbits);
131 /* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there
132 is no spurious underflow here even without fma. */
133 return eval_as_double(scale + scale * tmp);
134}
lib/libc/musl/src/math/expf.c deleted-80
......@@ -1,80 +0,0 @@
1/*
2 * Single-precision e^x function.
3 *
4 * Copyright (c) 2017-2018, Arm Limited.
5 * SPDX-License-Identifier: MIT
6 */
7
8#include <math.h>
9#include <stdint.h>
10#include "libm.h"
11#include "exp2f_data.h"
12
13/*
14EXP2F_TABLE_BITS = 5
15EXP2F_POLY_ORDER = 3
16
17ULP error: 0.502 (nearest rounding.)
18Relative error: 1.69 * 2^-34 in [-ln2/64, ln2/64] (before rounding.)
19Wrong count: 170635 (all nearest rounding wrong results with fma.)
20Non-nearest ULP error: 1 (rounded ULP error)
21*/
22
23#define N (1 << EXP2F_TABLE_BITS)
24#define InvLn2N __exp2f_data.invln2_scaled
25#define T __exp2f_data.tab
26#define C __exp2f_data.poly_scaled
27
28static inline uint32_t top12(float x)
29{
30 return asuint(x) >> 20;
31}
32
33float expf(float x)
34{
35 uint32_t abstop;
36 uint64_t ki, t;
37 double_t kd, xd, z, r, r2, y, s;
38
39 xd = (double_t)x;
40 abstop = top12(x) & 0x7ff;
41 if (predict_false(abstop >= top12(88.0f))) {
42 /* |x| >= 88 or x is nan. */
43 if (asuint(x) == asuint(-INFINITY))
44 return 0.0f;
45 if (abstop >= top12(INFINITY))
46 return x + x;
47 if (x > 0x1.62e42ep6f) /* x > log(0x1p128) ~= 88.72 */
48 return __math_oflowf(0);
49 if (x < -0x1.9fe368p6f) /* x < log(0x1p-150) ~= -103.97 */
50 return __math_uflowf(0);
51 }
52
53 /* x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k. */
54 z = InvLn2N * xd;
55
56 /* Round and convert z to int, the result is in [-150*N, 128*N] and
57 ideally ties-to-even rule is used, otherwise the magnitude of r
58 can be bigger which gives larger approximation error. */
59#if TOINT_INTRINSICS
60 kd = roundtoint(z);
61 ki = converttoint(z);
62#else
63# define SHIFT __exp2f_data.shift
64 kd = eval_as_double(z + SHIFT);
65 ki = asuint64(kd);
66 kd -= SHIFT;
67#endif
68 r = z - kd;
69
70 /* exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */
71 t = T[ki % N];
72 t += ki << (52 - EXP2F_TABLE_BITS);
73 s = asdouble(t);
74 z = C[0] * r + C[1];
75 r2 = r * r;
76 y = C[2] * r + 1;
77 y = z * r2 + y;
78 y = y * s;
79 return eval_as_float(y);
80}
src/libs/mingw.zig-1
......@@ -997,7 +997,6 @@ const mingw32_x86_src = [_][]const u8{
997997const mingw32_x86_32_src = [_][]const u8{
998998 // ucrtbase
999999 "math" ++ path.sep_str ++ "coshf.c",
1000 "math" ++ path.sep_str ++ "expf.c",
10011000 "math" ++ path.sep_str ++ "log10f.c",
10021001 "math" ++ path.sep_str ++ "logf.c",
10031002 "math" ++ path.sep_str ++ "modff.c",
src/libs/musl.zig-2
......@@ -903,9 +903,7 @@ const src_files = [_][]const u8{
903903 "musl/src/math/exp2f.c",
904904 "musl/src/math/exp2f_data.c",
905905 "musl/src/math/exp2l.c",
906 "musl/src/math/exp.c",
907906 "musl/src/math/exp_data.c",
908 "musl/src/math/expf.c",
909907 "musl/src/math/expl.c",
910908 "musl/src/math/expm1.c",
911909 "musl/src/math/expm1f.c",
src/libs/wasi_libc.zig-2
......@@ -743,9 +743,7 @@ const libc_top_half_src_files = [_][]const u8{
743743 "musl/src/math/exp2f.c",
744744 "musl/src/math/exp2f_data.c",
745745 "musl/src/math/exp2l.c",
746 "musl/src/math/exp.c",
747746 "musl/src/math/exp_data.c",
748 "musl/src/math/expf.c",
749747 "musl/src/math/expl.c",
750748 "musl/src/math/expm1.c",
751749 "musl/src/math/expm1f.c",