Bug 1358149 add log10f and hypotf from fdlibm r=arai

These operations are used from dom/media/webaudio.

Differential Revision: https://phabricator.services.mozilla.com/D185779
This commit is contained in:
Karl Tomlinson 2023-08-10 11:16:39 +00:00
parent bdaa3415cc
commit d7103695d6
13 changed files with 292 additions and 9 deletions

View File

@ -44,7 +44,9 @@ vendoring:
- e_exp.c
- e_expf.c
- e_hypot.c
- e_hypotf.c
- e_log10.c
- e_log10f.c
- e_log2.c
- e_log.c
- e_logf.c
@ -59,6 +61,7 @@ vendoring:
- k_exp.c
- k_expf.c
- k_log.h
- k_logf.h
- k_rem_pio2.c
- k_sin.c
- k_sinf.c

View File

@ -1,7 +1,7 @@
diff --git a/fdlibm.h b/fdlibm.h
--- a/fdlibm.h
+++ b/fdlibm.h
@@ -12,504 +12,66 @@
@@ -12,504 +12,68 @@
/*
* from: @(#)fdlibm.h 5.1 93/09/24
* $FreeBSD$
@ -348,7 +348,7 @@ diff --git a/fdlibm.h b/fdlibm.h
-float frexpf(float, int *); /* fundamentally !__pure2 */
-int ilogbf(float) __pure2;
-float ldexpf(float, int);
-float log10f(float);
float log10f(float);
-float log1pf(float);
-float log2f(float);
float logf(float);
@ -366,7 +366,7 @@ diff --git a/fdlibm.h b/fdlibm.h
-
-float erff(float);
-float erfcf(float);
-float hypotf(float, float);
float hypotf(float, float);
-float lgammaf(float);
-float tgammaf(float);
-

View File

@ -24,10 +24,10 @@
double atan2(double, double);
double cos(double);
double sin(double);
@@ -69,9 +72,9 @@
float ceilf(float);
@@ -71,9 +74,9 @@
float fabsf(float);
float floorf(float);
float hypotf(float, float);
float nearbyintf(float);
float rintf(float);
float scalbnf(float, int);

View File

@ -1,3 +1,5 @@
"math.h" is still included in e_hypotf.cpp for fabsl() and
in e_log10f.cpp for float_t.
diff --git a/e_acos.cpp b/e_acos.cpp
--- a/e_acos.cpp
+++ b/e_acos.cpp

View File

@ -3,7 +3,7 @@ to C code.
diff --git a/fdlibm.h b/fdlibm.h
--- a/fdlibm.h
+++ b/fdlibm.h
@@ -16,65 +16,65 @@
@@ -16,67 +16,67 @@
#ifndef mozilla_imported_fdlibm_h
#define mozilla_imported_fdlibm_h
@ -73,6 +73,7 @@ diff --git a/fdlibm.h b/fdlibm.h
-float tanf(float);
-float exp2f(float);
-float expf(float);
-float log10f(float);
-float logf(float);
-float powf(float, float);
-float sqrtf(float);
@ -98,6 +99,7 @@ diff --git a/fdlibm.h b/fdlibm.h
+float fdlibm_tanf(float);
+float fdlibm_exp2f(float);
+float fdlibm_expf(float);
+float fdlibm_log10f(float);
+float fdlibm_logf(float);
+float fdlibm_powf(float, float);
+float fdlibm_sqrtf(float);
@ -105,6 +107,7 @@ diff --git a/fdlibm.h b/fdlibm.h
-float ceilf(float);
-float fabsf(float);
-float floorf(float);
-float hypotf(float, float);
-float nearbyintf(float);
-float rintf(float);
-float scalbnf(float, int);
@ -112,6 +115,7 @@ diff --git a/fdlibm.h b/fdlibm.h
+float fdlibm_ceilf(float);
+float fdlibm_fabsf(float);
+float fdlibm_floorf(float);
+float fdlibm_hypotf(float, float);
+float fdlibm_nearbyintf(float);
+float fdlibm_rintf(float);
+float fdlibm_scalbnf(float, int);
@ -121,7 +125,7 @@ diff --git a/fdlibm.h b/fdlibm.h
diff --git a/math_private.h b/math_private.h
--- a/math_private.h
+++ b/math_private.h
@@ -867,16 +867,67 @@ irintl(long double x)
@@ -867,16 +867,69 @@ irintl(long double x)
#define __ieee754_j1f j1f
#define __ieee754_y0f y0f
#define __ieee754_y1f y1f
@ -153,6 +157,7 @@ diff --git a/math_private.h b/math_private.h
+#define log fdlibm_log
+#define logf fdlibm_logf
+#define log10 fdlibm_log10
+#define log10f fdlibm_log10f
+#define pow fdlibm_pow
+#define powf fdlibm_powf
+#define ceil fdlibm_ceil
@ -166,6 +171,7 @@ diff --git a/math_private.h b/math_private.h
+#define cbrt fdlibm_cbrt
+#define expm1 fdlibm_expm1
+#define hypot fdlibm_hypot
+#define hypotf fdlibm_hypotf
+#define log1p fdlibm_log1p
+#define log2 fdlibm_log2
+#define scalb fdlibm_scalb

View File

@ -190,6 +190,30 @@ diff --git a/e_hypot.cpp b/e_hypot.cpp
* has error less than sqrt(2)/2 ulp, than
* sqrt(z) has error less than 1 ulp (exercise).
*
diff --git a/e_hypotf.cpp b/e_hypotf.cpp
--- a/e_hypotf.cpp
+++ b/e_hypotf.cpp
@@ -8,18 +8,18 @@
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+//#include <sys/cdefs.h>
+//__FBSDID("$FreeBSD$");
#include "math.h"
#include "math_private.h"
float
__ieee754_hypotf(float x, float y)
{
float a,b,t1,t2,y1,y2,w;
diff --git a/e_log.cpp b/e_log.cpp
--- a/e_log.cpp
+++ b/e_log.cpp
@ -253,6 +277,30 @@ diff --git a/e_log10.cpp b/e_log10.cpp
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
static const double zero = 0.0;
diff --git a/e_log10f.cpp b/e_log10f.cpp
--- a/e_log10f.cpp
+++ b/e_log10f.cpp
@@ -4,18 +4,18 @@
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+//#include <sys/cdefs.h>
+//__FBSDID("$FreeBSD$");
/*
* Float version of e_log10.c. See the latter for most comments.
*/
#include "math.h"
#include "math_private.h"
#include "k_logf.h"
diff --git a/e_log2.cpp b/e_log2.cpp
--- a/e_log2.cpp
+++ b/e_log2.cpp
@ -426,6 +474,30 @@ diff --git a/k_log.h b/k_log.h
* The following describes the overall strategy for computing
* logarithms in base e. The argument reduction and adding the final
* term of the polynomial are done by the caller for increased accuracy
diff --git a/k_logf.h b/k_logf.h
--- a/k_logf.h
+++ b/k_logf.h
@@ -4,18 +4,18 @@
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+//#include <sys/cdefs.h>
+//__FBSDID("$FreeBSD$");
/*
* Float version of k_log.h. See the latter for most comments.
*/
static const float
/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */
diff --git a/k_rem_pio2.cpp b/k_rem_pio2.cpp
--- a/k_rem_pio2.cpp
+++ b/k_rem_pio2.cpp

View File

@ -22,10 +22,10 @@ diff --git a/fdlibm.h b/fdlibm.h
double fdlibm_sin(double);
double fdlibm_tan(double);
@@ -72,9 +74,13 @@ float fdlibm_sqrtf(float);
float fdlibm_ceilf(float);
@@ -74,9 +76,13 @@ float fdlibm_sqrtf(float);
float fdlibm_fabsf(float);
float fdlibm_floorf(float);
float fdlibm_hypotf(float, float);
float fdlibm_nearbyintf(float);
float fdlibm_rintf(float);
float fdlibm_scalbnf(float, int);

View File

@ -0,0 +1,83 @@
/* e_hypotf.c -- float version of e_hypot.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
//#include <sys/cdefs.h>
//__FBSDID("$FreeBSD$");
#include "math.h"
#include "math_private.h"
float
__ieee754_hypotf(float x, float y)
{
float a,b,t1,t2,y1,y2,w;
int32_t j,k,ha,hb;
GET_FLOAT_WORD(ha,x);
ha &= 0x7fffffff;
GET_FLOAT_WORD(hb,y);
hb &= 0x7fffffff;
if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
a = fabsf(a);
b = fabsf(b);
if((ha-hb)>0xf000000) {return a+b;} /* x/y > 2**30 */
k=0;
if(ha > 0x58800000) { /* a>2**50 */
if(ha >= 0x7f800000) { /* Inf or NaN */
/* Use original arg order iff result is NaN; quieten sNaNs. */
w = fabsl(x+0.0L)-fabsf(y+0);
if(ha == 0x7f800000) w = a;
if(hb == 0x7f800000) w = b;
return w;
}
/* scale a and b by 2**-68 */
ha -= 0x22000000; hb -= 0x22000000; k += 68;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
if(hb < 0x26800000) { /* b < 2**-50 */
if(hb <= 0x007fffff) { /* subnormal b or 0 */
if(hb==0) return a;
SET_FLOAT_WORD(t1,0x7e800000); /* t1=2^126 */
b *= t1;
a *= t1;
k -= 126;
} else { /* scale a and b by 2^68 */
ha += 0x22000000; /* a *= 2^68 */
hb += 0x22000000; /* b *= 2^68 */
k -= 68;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
}
/* medium size a and b */
w = a-b;
if (w>b) {
SET_FLOAT_WORD(t1,ha&0xfffff000);
t2 = a-t1;
w = __ieee754_sqrtf(t1*t1-(b*(-b)-t2*(a+t1)));
} else {
a = a+a;
SET_FLOAT_WORD(y1,hb&0xfffff000);
y2 = b - y1;
SET_FLOAT_WORD(t1,(ha+0x00800000)&0xfffff000);
t2 = a - t1;
w = __ieee754_sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
}
if(k!=0) {
SET_FLOAT_WORD(t1,(127+k)<<23);
return t1*w;
} else return w;
}

View File

@ -0,0 +1,72 @@
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
//#include <sys/cdefs.h>
//__FBSDID("$FreeBSD$");
/*
* Float version of e_log10.c. See the latter for most comments.
*/
#include "math.h"
#include "math_private.h"
#include "k_logf.h"
static const float
two25 = 3.3554432000e+07, /* 0x4c000000 */
ivln10hi = 4.3432617188e-01, /* 0x3ede6000 */
ivln10lo = -3.1689971365e-05, /* 0xb804ead9 */
log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */
log10_2lo = 7.9034151668e-07; /* 0x355427db */
static const float zero = 0.0;
static volatile float vzero = 0.0;
float
__ieee754_log10f(float x)
{
float f,hfsq,hi,lo,r,y;
int32_t i,k,hx;
GET_FLOAT_WORD(hx,x);
k=0;
if (hx < 0x00800000) { /* x < 2**-126 */
if ((hx&0x7fffffff)==0)
return -two25/vzero; /* log(+-0)=-inf */
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
k -= 25; x *= two25; /* subnormal number, scale up x */
GET_FLOAT_WORD(hx,x);
}
if (hx >= 0x7f800000) return x+x;
if (hx == 0x3f800000)
return zero; /* log(1) = +0 */
k += (hx>>23)-127;
hx &= 0x007fffff;
i = (hx+(0x4afb0d))&0x800000;
SET_FLOAT_WORD(x,hx|(i^0x3f800000)); /* normalize x or x/2 */
k += (i>>23);
y = (float)k;
f = x - (float)1.0;
hfsq = (float)0.5*f*f;
r = k_log1pf(f);
/* See e_log2f.c and e_log2.c for details. */
if (sizeof(float_t) > sizeof(float))
return (r - hfsq + f) * ((float_t)ivln10lo + ivln10hi) +
y * ((float_t)log10_2lo + log10_2hi);
hi = f - hfsq;
GET_FLOAT_WORD(hx,hi);
SET_FLOAT_WORD(hi,hx&0xfffff000);
lo = (f - hi) - hfsq + r;
return y*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi + hi*ivln10hi +
y*log10_2hi;
}

View File

@ -69,6 +69,7 @@ float fdlibm_sinf(float);
float fdlibm_tanf(float);
float fdlibm_exp2f(float);
float fdlibm_expf(float);
float fdlibm_log10f(float);
float fdlibm_logf(float);
float fdlibm_powf(float, float);
float fdlibm_sqrtf(float);
@ -76,6 +77,7 @@ float fdlibm_sqrtf(float);
float fdlibm_ceilf(float);
float fdlibm_fabsf(float);
float fdlibm_floorf(float);
float fdlibm_hypotf(float, float);
float fdlibm_nearbyintf(float);
float fdlibm_rintf(float);
float fdlibm_scalbnf(float, int);

View File

@ -0,0 +1,39 @@
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
//#include <sys/cdefs.h>
//__FBSDID("$FreeBSD$");
/*
* Float version of k_log.h. See the latter for most comments.
*/
static const float
/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */
Lg2 = 0xccce13.0p-25, /* 0.40000972152 */
Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */
Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */
static inline float
k_log1pf(float f)
{
float hfsq,s,z,R,w,t1,t2;
s = f/((float)2.0+f);
z = s*s;
w = z*z;
t1= w*(Lg2+w*Lg4);
t2= z*(Lg1+w*Lg3);
R = t2+t1;
hfsq=(float)0.5*f*f;
return s*(hfsq+R);
}

View File

@ -893,6 +893,7 @@ irintl(long double x)
#define log fdlibm_log
#define logf fdlibm_logf
#define log10 fdlibm_log10
#define log10f fdlibm_log10f
#define pow fdlibm_pow
#define powf fdlibm_powf
#define ceil fdlibm_ceil
@ -906,6 +907,7 @@ irintl(long double x)
#define cbrt fdlibm_cbrt
#define expm1 fdlibm_expm1
#define hypot fdlibm_hypot
#define hypotf fdlibm_hypotf
#define log1p fdlibm_log1p
#define log2 fdlibm_log2
#define scalb fdlibm_scalb

View File

@ -44,8 +44,10 @@ SOURCES += [
'e_exp.cpp',
'e_expf.cpp',
'e_hypot.cpp',
'e_hypotf.cpp',
'e_log.cpp',
'e_log10.cpp',
'e_log10f.cpp',
'e_log2.cpp',
'e_logf.cpp',
'e_pow.cpp',