Fix code style and comments of new math code
Synchronize code style and comments with Arm Optimized Routines, there are no code changes in this patch. This ensures different projects using the same code have consistent code style so bug fix patches can be applied more easily.
This commit is contained in:
parent
6a3e08a53e
commit
cbe50607fb
@ -45,6 +45,13 @@
|
|||||||
#define C5 __exp_data.poly[8 - EXP_POLY_ORDER]
|
#define C5 __exp_data.poly[8 - EXP_POLY_ORDER]
|
||||||
#define C6 __exp_data.poly[9 - EXP_POLY_ORDER]
|
#define C6 __exp_data.poly[9 - EXP_POLY_ORDER]
|
||||||
|
|
||||||
|
/* Handle cases that may overflow or underflow when computing the result that
|
||||||
|
is scale*(1+TMP) without intermediate rounding. The bit representation of
|
||||||
|
scale is in SBITS, however it has a computed exponent that may have
|
||||||
|
overflown into the sign bit so that needs to be adjusted before using it as
|
||||||
|
a double. (int32_t)KI is the k used in the argument reduction and exponent
|
||||||
|
adjustment of scale, positive k here means the result may overflow and
|
||||||
|
negative k means the result may underflow. */
|
||||||
static inline double
|
static inline double
|
||||||
specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
|
specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
|
||||||
{
|
{
|
||||||
@ -83,6 +90,7 @@ specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
|
|||||||
return check_uflow (y);
|
return check_uflow (y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Top 12 bits of a double (sign and exponent bits). */
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
top12 (double x)
|
top12 (double x)
|
||||||
{
|
{
|
||||||
@ -158,7 +166,7 @@ exp (double x)
|
|||||||
if (unlikely (abstop == 0))
|
if (unlikely (abstop == 0))
|
||||||
return specialcase (tmp, sbits, ki);
|
return specialcase (tmp, sbits, ki);
|
||||||
scale = asdouble (sbits);
|
scale = asdouble (sbits);
|
||||||
/* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there
|
/* Note: tmp == 0 or |tmp| > 2^-65 and scale > 2^-739, so there
|
||||||
is no spurious underflow here even without fma. */
|
is no spurious underflow here even without fma. */
|
||||||
return scale + scale * tmp;
|
return scale + scale * tmp;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,13 @@
|
|||||||
#define C5 __exp_data.exp2_poly[4]
|
#define C5 __exp_data.exp2_poly[4]
|
||||||
#define C6 __exp_data.exp2_poly[5]
|
#define C6 __exp_data.exp2_poly[5]
|
||||||
|
|
||||||
|
/* Handle cases that may overflow or underflow when computing the result that
|
||||||
|
is scale*(1+TMP) without intermediate rounding. The bit representation of
|
||||||
|
scale is in SBITS, however it has a computed exponent that may have
|
||||||
|
overflown into the sign bit so that needs to be adjusted before using it as
|
||||||
|
a double. (int32_t)KI is the k used in the argument reduction and exponent
|
||||||
|
adjustment of scale, positive k here means the result may overflow and
|
||||||
|
negative k means the result may underflow. */
|
||||||
static inline double
|
static inline double
|
||||||
specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
|
specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
|
||||||
{
|
{
|
||||||
@ -81,6 +88,7 @@ specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
|
|||||||
return check_uflow (y);
|
return check_uflow (y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Top 12 bits of a double (sign and exponent bits). */
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
top12 (double x)
|
top12 (double x)
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#define N (1 << LOG_TABLE_BITS)
|
#define N (1 << LOG_TABLE_BITS)
|
||||||
#define OFF 0x3fe6000000000000
|
#define OFF 0x3fe6000000000000
|
||||||
|
|
||||||
|
/* Top 16 bits of a double. */
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
top16 (double x)
|
top16 (double x)
|
||||||
{
|
{
|
||||||
@ -168,7 +169,10 @@ log (double x)
|
|||||||
#if LOG_POLY_ORDER == 6
|
#if LOG_POLY_ORDER == 6
|
||||||
y = lo + r2 * A[0] + r * r2 * (A[1] + r * A[2] + r2 * (A[3] + r * A[4])) + hi;
|
y = lo + r2 * A[0] + r * r2 * (A[1] + r * A[2] + r2 * (A[3] + r * A[4])) + hi;
|
||||||
#elif LOG_POLY_ORDER == 7
|
#elif LOG_POLY_ORDER == 7
|
||||||
y = lo + r2*(A[0] + r*A[1] + r2*(A[2] + r*A[3]) + r2*r2*(A[4] + r*A[5])) + hi;
|
y = lo
|
||||||
|
+ r2 * (A[0] + r * A[1] + r2 * (A[2] + r * A[3])
|
||||||
|
+ r2 * r2 * (A[4] + r * A[5]))
|
||||||
|
+ hi;
|
||||||
#endif
|
#endif
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#define N (1 << LOG2_TABLE_BITS)
|
#define N (1 << LOG2_TABLE_BITS)
|
||||||
#define OFF 0x3fe6000000000000
|
#define OFF 0x3fe6000000000000
|
||||||
|
|
||||||
|
/* Top 16 bits of a double. */
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
top16 (double x)
|
top16 (double x)
|
||||||
{
|
{
|
||||||
|
@ -233,28 +233,48 @@ eval_as_double (double x)
|
|||||||
# define unlikely(x) (x)
|
# define unlikely(x) (x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Error handling tail calls for special cases, with sign argument. */
|
/* Error handling tail calls for special cases, with a sign argument.
|
||||||
|
The sign of the return value is set if the argument is non-zero. */
|
||||||
|
|
||||||
|
/* The result overflows. */
|
||||||
HIDDEN float __math_oflowf (uint32_t);
|
HIDDEN float __math_oflowf (uint32_t);
|
||||||
|
/* The result underflows to 0 in nearest rounding mode. */
|
||||||
HIDDEN float __math_uflowf (uint32_t);
|
HIDDEN float __math_uflowf (uint32_t);
|
||||||
|
/* The result underflows to 0 in some directed rounding mode only. */
|
||||||
HIDDEN float __math_may_uflowf (uint32_t);
|
HIDDEN float __math_may_uflowf (uint32_t);
|
||||||
|
/* Division by zero. */
|
||||||
HIDDEN float __math_divzerof (uint32_t);
|
HIDDEN float __math_divzerof (uint32_t);
|
||||||
|
/* The result overflows. */
|
||||||
HIDDEN double __math_oflow (uint32_t);
|
HIDDEN double __math_oflow (uint32_t);
|
||||||
|
/* The result underflows to 0 in nearest rounding mode. */
|
||||||
HIDDEN double __math_uflow (uint32_t);
|
HIDDEN double __math_uflow (uint32_t);
|
||||||
|
/* The result underflows to 0 in some directed rounding mode only. */
|
||||||
HIDDEN double __math_may_uflow (uint32_t);
|
HIDDEN double __math_may_uflow (uint32_t);
|
||||||
|
/* Division by zero. */
|
||||||
HIDDEN double __math_divzero (uint32_t);
|
HIDDEN double __math_divzero (uint32_t);
|
||||||
|
|
||||||
/* Error handling using input checking. */
|
/* Error handling using input checking. */
|
||||||
|
|
||||||
|
/* Invalid input unless it is a quiet NaN. */
|
||||||
HIDDEN float __math_invalidf (float);
|
HIDDEN float __math_invalidf (float);
|
||||||
|
/* Invalid input unless it is a quiet NaN. */
|
||||||
HIDDEN double __math_invalid (double);
|
HIDDEN double __math_invalid (double);
|
||||||
|
|
||||||
/* Error handling using output checking, only for errno setting. */
|
/* Error handling using output checking, only for errno setting. */
|
||||||
|
|
||||||
|
/* Check if the result overflowed to infinity. */
|
||||||
HIDDEN double __math_check_oflow (double);
|
HIDDEN double __math_check_oflow (double);
|
||||||
|
/* Check if the result underflowed to 0. */
|
||||||
HIDDEN double __math_check_uflow (double);
|
HIDDEN double __math_check_uflow (double);
|
||||||
|
|
||||||
|
/* Check if the result overflowed to infinity. */
|
||||||
static inline double
|
static inline double
|
||||||
check_oflow (double x)
|
check_oflow (double x)
|
||||||
{
|
{
|
||||||
return WANT_ERRNO ? __math_check_oflow (x) : x;
|
return WANT_ERRNO ? __math_check_oflow (x) : x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check if the result underflowed to 0. */
|
||||||
static inline double
|
static inline double
|
||||||
check_uflow (double x)
|
check_uflow (double x)
|
||||||
{
|
{
|
||||||
@ -324,7 +344,8 @@ extern const struct powf_log2_data
|
|||||||
#define EXP_USE_TOINT_NARROW 0
|
#define EXP_USE_TOINT_NARROW 0
|
||||||
#define EXP2_POLY_ORDER 5
|
#define EXP2_POLY_ORDER 5
|
||||||
#define EXP2_POLY_WIDE 0
|
#define EXP2_POLY_WIDE 0
|
||||||
extern const struct exp_data {
|
extern const struct exp_data
|
||||||
|
{
|
||||||
double invln2N;
|
double invln2N;
|
||||||
double shift;
|
double shift;
|
||||||
double negln2hiN;
|
double negln2hiN;
|
||||||
@ -338,7 +359,8 @@ extern const struct exp_data {
|
|||||||
#define LOG_TABLE_BITS 7
|
#define LOG_TABLE_BITS 7
|
||||||
#define LOG_POLY_ORDER 6
|
#define LOG_POLY_ORDER 6
|
||||||
#define LOG_POLY1_ORDER 12
|
#define LOG_POLY1_ORDER 12
|
||||||
extern const struct log_data {
|
extern const struct log_data
|
||||||
|
{
|
||||||
double ln2hi;
|
double ln2hi;
|
||||||
double ln2lo;
|
double ln2lo;
|
||||||
double poly[LOG_POLY_ORDER - 1]; /* First coefficient is 1. */
|
double poly[LOG_POLY_ORDER - 1]; /* First coefficient is 1. */
|
||||||
@ -352,7 +374,8 @@ extern const struct log_data {
|
|||||||
#define LOG2_TABLE_BITS 6
|
#define LOG2_TABLE_BITS 6
|
||||||
#define LOG2_POLY_ORDER 7
|
#define LOG2_POLY_ORDER 7
|
||||||
#define LOG2_POLY1_ORDER 11
|
#define LOG2_POLY1_ORDER 11
|
||||||
extern const struct log2_data {
|
extern const struct log2_data
|
||||||
|
{
|
||||||
double invln2hi;
|
double invln2hi;
|
||||||
double invln2lo;
|
double invln2lo;
|
||||||
double poly[LOG2_POLY_ORDER - 1];
|
double poly[LOG2_POLY_ORDER - 1];
|
||||||
@ -365,7 +388,8 @@ extern const struct log2_data {
|
|||||||
|
|
||||||
#define POW_LOG_TABLE_BITS 7
|
#define POW_LOG_TABLE_BITS 7
|
||||||
#define POW_LOG_POLY_ORDER 8
|
#define POW_LOG_POLY_ORDER 8
|
||||||
extern const struct pow_log_data {
|
extern const struct pow_log_data
|
||||||
|
{
|
||||||
double ln2hi;
|
double ln2hi;
|
||||||
double ln2lo;
|
double ln2lo;
|
||||||
double poly[POW_LOG_POLY_ORDER - 1]; /* First coefficient is 1. */
|
double poly[POW_LOG_POLY_ORDER - 1]; /* First coefficient is 1. */
|
||||||
|
@ -46,12 +46,16 @@ ulperr_exp: 0.509 ULP (ULP error of exp, 0.511 ULP without fma)
|
|||||||
#define N (1 << POW_LOG_TABLE_BITS)
|
#define N (1 << POW_LOG_TABLE_BITS)
|
||||||
#define OFF 0x3fe6955500000000
|
#define OFF 0x3fe6955500000000
|
||||||
|
|
||||||
|
/* Top 12 bits of a double (sign and exponent bits). */
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
top12 (double x)
|
top12 (double x)
|
||||||
{
|
{
|
||||||
return asuint64 (x) >> 52;
|
return asuint64 (x) >> 52;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Compute y+tail = log(x) where the rounded result is y and tail has about
|
||||||
|
additional 15 bits precision. The bit representation of x if in ix, but
|
||||||
|
normalized in the subnormal range using sign bit too for the exponent. */
|
||||||
static inline double_t
|
static inline double_t
|
||||||
log_inline (uint64_t ix, double_t *tail)
|
log_inline (uint64_t ix, double_t *tail)
|
||||||
{
|
{
|
||||||
@ -111,7 +115,8 @@ log_inline (uint64_t ix, double_t *tail)
|
|||||||
#endif
|
#endif
|
||||||
/* p = log1p(r) - r - A[0]*r*r. */
|
/* p = log1p(r) - r - A[0]*r*r. */
|
||||||
#if POW_LOG_POLY_ORDER == 8
|
#if POW_LOG_POLY_ORDER == 8
|
||||||
p = ar3*(A[1] + r*A[2] + ar2*(A[3] + r*A[4] + ar2*(A[5] + r*A[6])));
|
p = (ar3
|
||||||
|
* (A[1] + r * A[2] + ar2 * (A[3] + r * A[4] + ar2 * (A[5] + r * A[6]))));
|
||||||
#endif
|
#endif
|
||||||
lo = lo1 + lo2 + lo3 + lo4 + p;
|
lo = lo1 + lo2 + lo3 + lo4 + p;
|
||||||
y = hi + lo;
|
y = hi + lo;
|
||||||
@ -133,6 +138,13 @@ log_inline (uint64_t ix, double_t *tail)
|
|||||||
#define C5 __exp_data.poly[8 - EXP_POLY_ORDER]
|
#define C5 __exp_data.poly[8 - EXP_POLY_ORDER]
|
||||||
#define C6 __exp_data.poly[9 - EXP_POLY_ORDER]
|
#define C6 __exp_data.poly[9 - EXP_POLY_ORDER]
|
||||||
|
|
||||||
|
/* Handle cases that may overflow or underflow when computing the result that
|
||||||
|
is scale*(1+TMP) without intermediate rounding. The bit representation of
|
||||||
|
scale is in SBITS, however it has a computed exponent that may have
|
||||||
|
overflown into the sign bit so that needs to be adjusted before using it as
|
||||||
|
a double. (int32_t)KI is the k used in the argument reduction and exponent
|
||||||
|
adjustment of scale, positive k here means the result may overflow and
|
||||||
|
negative k means the result may underflow. */
|
||||||
static inline double
|
static inline double
|
||||||
specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
|
specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
|
||||||
{
|
{
|
||||||
@ -176,6 +188,8 @@ specialcase (double_t tmp, uint64_t sbits, uint64_t ki)
|
|||||||
|
|
||||||
#define SIGN_BIAS (0x800 << EXP_TABLE_BITS)
|
#define SIGN_BIAS (0x800 << EXP_TABLE_BITS)
|
||||||
|
|
||||||
|
/* Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.
|
||||||
|
The sign_bias argument is SIGN_BIAS or 0 and sets the sign to -1 or 1. */
|
||||||
static inline double
|
static inline double
|
||||||
exp_inline (double x, double xtail, uint32_t sign_bias)
|
exp_inline (double x, double xtail, uint32_t sign_bias)
|
||||||
{
|
{
|
||||||
@ -268,6 +282,7 @@ checkint (uint64_t iy)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns 1 if input is the bit representation of 0, infinity or nan. */
|
||||||
static inline int
|
static inline int
|
||||||
zeroinfnan (uint64_t i)
|
zeroinfnan (uint64_t i)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user