Files
clang-p2996/libc/AOR_v20.02/math/math_errf.c
Kristof Beyls 0928368f62 [libc] Provide Arm Optimized Routines for the LLVM libc project.
This adds the Arm Optimized Routines (see
https://github.com/ARM-software/optimized-routines) source code under the
the LLVM license. The version of the code provided in this patch is v20.02
of the Arm Optimized Routines project.

This entire contribution is being committed as is even though it does
not currently fit the LLVM libc model and does not follow the LLVM
coding style. In the near future, implementations from this patch will be
moved over to their right place in the LLVM-libc tree. This will be done
over many small patches, all of which will go through the normal LLVM code
review process. See this libc-dev post for the plan:
http://lists.llvm.org/pipermail/libc-dev/2020-March/000044.html

Differential revision of the original upload: https://reviews.llvm.org/D75355
2020-03-16 12:19:31 -07:00

68 lines
1.4 KiB
C

/*
* Single-precision math error handling.
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "math_config.h"
#if WANT_ERRNO
#include <errno.h>
/* NOINLINE reduces code size and avoids making math functions non-leaf
when the error handling is inlined. */
NOINLINE static float
with_errnof (float y, int e)
{
errno = e;
return y;
}
#else
#define with_errnof(x, e) (x)
#endif
/* NOINLINE reduces code size. */
NOINLINE static float
xflowf (uint32_t sign, float y)
{
y = eval_as_float (opt_barrier_float (sign ? -y : y) * y);
return with_errnof (y, ERANGE);
}
HIDDEN float
__math_uflowf (uint32_t sign)
{
return xflowf (sign, 0x1p-95f);
}
#if WANT_ERRNO_UFLOW
/* Underflows to zero in some non-nearest rounding mode, setting errno
is valid even if the result is non-zero, but in the subnormal range. */
HIDDEN float
__math_may_uflowf (uint32_t sign)
{
return xflowf (sign, 0x1.4p-75f);
}
#endif
HIDDEN float
__math_oflowf (uint32_t sign)
{
return xflowf (sign, 0x1p97f);
}
HIDDEN float
__math_divzerof (uint32_t sign)
{
float y = opt_barrier_float (sign ? -1.0f : 1.0f) / 0.0f;
return with_errnof (y, ERANGE);
}
HIDDEN float
__math_invalidf (float x)
{
float y = (x - x) / (x - x);
return isnan (x) ? y : with_errnof (y, EDOM);
}