[PATCH 15/25] math: Use asinh from CORE-MATH

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Sep 15 17:46:01 GMT 2025



On 10/09/25 00:15, DJ Delorie wrote:
> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
>> +/* Correctly-rounded inverse hyperbolic sine function for the
>> +   binary64 floating point format.
> 
> Can this be squeezed into one line?  I see other files with multi-line
> "first lines" but I don't know if the one-line-description is a rule or
> a guideline...

Ack, but I think we don't have such constraint.

> 
>> +static inline double
>> +fasttwosum (double x, double y, double *e)
>> +{
>> +  double s = x + y, z = s - x;
>> +  *e = y - z;
>> +  return s;
>> +}
>> +
>> +static inline double
>> +adddd (double xh, double xl, double ch, double cl, double *l)
>> +{
>> +  double s = xh + ch, d = s - xh;
>> +  *l = ((ch - d) + (xh + (d - s))) + (xl + cl);
>> +  return s;
>> +}
>> +
>> +static inline double
>> +muldd (double xh, double xl, double ch, double cl, double *l)
>> +{
>> +  double ahlh = ch * xl, alhh = cl * xh, ahhh = ch * xh,
>> +	 ahhl = fma (ch, xh, -ahhh);
>> +  ahhl += alhh + ahlh;
>> +  ch = ahhh + ahhl;
>> +  *l = (ahhh - ch) + ahhl;
>> +  return ch;
>> +}
>> +
>> +static inline double
>> +mulddd (double xh, double xl, double ch, double *l)
>> +{
>> +  double ahlh = ch * xl, ahhh = ch * xh, ahhl = fma (ch, xh, -ahhh);
>> +  ahhl += ahlh;
>> +  ch = ahhh + ahhl;
>> +  *l = (ahhh - ch) + ahhl;
>> +  return ch;
>> +}
>> +
>> +static inline double
>> +polydd (double xh, double xl, int n, const double c[][2], double *l)
>> +{
>> +  int i = n - 1;
>> +  double ch = c[i][0] + *l, cl = ((c[i][0] - ch) + *l) + c[i][1];
>> +  while (--i >= 0)
>> +    {
>> +      ch = muldd (xh, xl, ch, cl, &cl);
>> +      double th = ch + c[i][0], tl = (c[i][0] - th) + ch;
>> +      ch = th;
>> +      cl += tl + c[i][1];
>> +    }
>> +  *l = cl;
>> +  return ch;
>> +}
> 
> These could be moved to a common header, but that would be a CORE-MATH
> style decision.

It is CORE-MATH style decision to have independent implementations from
each other; so it should be easier to incorporate them in different
projects.

But it does not prevent us to consolidate common code and I agree that
having these on a common header make sense.

> 
>> +      double x2h = x * x, x2l = fma (x, x, -x2h);
>> +      double x3h = x2h * x, sl;
>> +      if (__glibc_unlikely (u < 0x3f93000000000000))
>> +	{ // |x| < 0x1.3p-6
>> +	  if (__glibc_unlikely (u < 0x3f30000000000000))
>> +	    { // |x| < 0x1p-12
>> +	      if (__glibc_unlikely (u < 0x3e5a000000000000))
>> +		{ // |x| < 0x1.ap-26
> 
> More bare hex values (UL or UINT64_C here).  There are more but I'll
> refrain from pointing them each out.

Ack.

> 
>> +    static
>> +    __attribute__ ((noinline)) double as_asinh_database (double x, double f)
> 
> style: 
> 
>> +    static __attribute__ ((noinline))
>> +    double as_asinh_database (double x, double f)
> 
> 

Ack.



More information about the Libc-alpha mailing list