[PATCH] libm/common: Split math_err.c and math_errf.c into per-function files
Jeff Johnston
jjohnstn@redhat.com
Sun Aug 18 16:46:00 GMT 2019
Hi Keith,
I am fine with the patch. Could you please resend the git formatted patch
as an attachment?
Thanks,
-- Jeff J.
On Tue, Aug 13, 2019 at 7:20 PM Keith Packard <keithp@keithp.com> wrote:
> This avoids bringing in additional code when using error functions
> without --gc-sections.
>
> Two functions from each file are now global and have been renamed to start
> with __math:
>
> with_errno → __math_with_errno
> with_errnof → __math_with_errnof
> xflow → __math_xflow
> xflowf → __math_xflowf
>
> There should be no functional changes to the resulting code.
>
> Signed-off-by: Keith Packard <keithp@keithp.com>
> ---
> newlib/libm/common/Makefile.am | 11 +++-
> newlib/libm/common/math_config.h | 17 +++++
> newlib/libm/common/math_err_check_oflow.c | 37 +++++++++++
> newlib/libm/common/math_err_check_uflow.c | 37 +++++++++++
> newlib/libm/common/math_err_divzero.c | 36 +++++++++++
> newlib/libm/common/math_err_invalid.c | 36 +++++++++++
> .../{math_err.c => math_err_may_uflow.c} | 64 +------------------
> newlib/libm/common/math_err_oflow.c | 35 ++++++++++
> newlib/libm/common/math_err_uflow.c | 35 ++++++++++
> newlib/libm/common/math_err_with_errno.c | 41 ++++++++++++
> newlib/libm/common/math_err_xflow.c | 36 +++++++++++
> newlib/libm/common/math_errf_divzerof.c | 39 +++++++++++
> newlib/libm/common/math_errf_invalidf.c | 39 +++++++++++
> .../{math_errf.c => math_errf_may_uflowf.c} | 52 +--------------
> newlib/libm/common/math_errf_oflowf.c | 36 +++++++++++
> newlib/libm/common/math_errf_uflowf.c | 38 +++++++++++
> newlib/libm/common/math_errf_with_errnof.c | 41 ++++++++++++
> newlib/libm/common/math_errf_xflowf.c | 38 +++++++++++
> 18 files changed, 552 insertions(+), 116 deletions(-)
> create mode 100644 newlib/libm/common/math_err_check_oflow.c
> create mode 100644 newlib/libm/common/math_err_check_uflow.c
> create mode 100644 newlib/libm/common/math_err_divzero.c
> create mode 100644 newlib/libm/common/math_err_invalid.c
> rename newlib/libm/common/{math_err.c => math_err_may_uflow.c} (60%)
> create mode 100644 newlib/libm/common/math_err_oflow.c
> create mode 100644 newlib/libm/common/math_err_uflow.c
> create mode 100644 newlib/libm/common/math_err_with_errno.c
> create mode 100644 newlib/libm/common/math_err_xflow.c
> create mode 100644 newlib/libm/common/math_errf_divzerof.c
> create mode 100644 newlib/libm/common/math_errf_invalidf.c
> rename newlib/libm/common/{math_errf.c => math_errf_may_uflowf.c} (66%)
> create mode 100644 newlib/libm/common/math_errf_oflowf.c
> create mode 100644 newlib/libm/common/math_errf_uflowf.c
> create mode 100644 newlib/libm/common/math_errf_with_errnof.c
> create mode 100644 newlib/libm/common/math_errf_xflowf.c
>
> diff --git a/newlib/libm/common/Makefile.am
> b/newlib/libm/common/Makefile.am
> index 1eef0236a..5f0d96258 100644
> --- a/newlib/libm/common/Makefile.am
> +++ b/newlib/libm/common/Makefile.am
> @@ -13,7 +13,11 @@ src = s_finite.c s_copysign.c s_modf.c
> s_scalbn.c \
> s_lrint.c s_llrint.c \
> s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c
> s_scalbln.c \
> s_signbit.c s_trunc.c \
> - exp.c exp2.c exp_data.c math_err.c log.c log_data.c log2.c
> log2_data.c \
> + exp.c exp2.c exp_data.c \
> + math_err_with_errno.c math_err_xflow.c math_err_uflow.c \
> + math_err_oflow.c math_err_divzero.c math_err_invalid.c \
> + math_err_may_uflow.c math_err_check_uflow.c math_err_check_oflow.c
> \
> + log.c log_data.c log2.c log2_data.c \
> pow.c pow_log_data.c
>
> fsrc = sf_finite.c sf_copysign.c sf_modf.c sf_scalbn.c \
> @@ -27,7 +31,10 @@ fsrc = sf_finite.c sf_copysign.c sf_modf.c
> sf_scalbn.c \
> sf_scalbln.c sf_trunc.c \
> sf_exp.c sf_exp2.c sf_exp2_data.c sf_log.c sf_log_data.c \
> sf_log2.c sf_log2_data.c sf_pow_log2_data.c sf_pow.c \
> - sinf.c cosf.c sincosf.c sincosf_data.c math_errf.c
> + sinf.c cosf.c sincosf.c sincosf_data.c \
> + math_errf_with_errnof.c math_errf_xflowf.c math_errf_uflowf.c \
> + math_errf_may_uflowf.c math_errf_oflowf.c math_errf_divzerof.c \
> + math_errf_invalidf.c
>
> lsrc = atanl.c cosl.c sinl.c tanl.c tanhl.c frexpl.c modfl.c ceill.c
> fabsl.c \
> floorl.c log1pl.c expm1l.c acosl.c asinl.c atan2l.c coshl.c
> sinhl.c \
> diff --git a/newlib/libm/common/math_config.h
> b/newlib/libm/common/math_config.h
> index 1a2d0f639..97f4b4d2c 100644
> --- a/newlib/libm/common/math_config.h
> +++ b/newlib/libm/common/math_config.h
> @@ -417,4 +417,21 @@ extern const struct pow_log_data
> struct {double invc, pad, logc, logctail;} tab[1 << POW_LOG_TABLE_BITS];
> } __pow_log_data HIDDEN;
>
> +#if WANT_ERRNO
> +HIDDEN double
> +__math_with_errno (double y, int e);
> +
> +HIDDEN float
> +__math_with_errnof (float y, int e);
> +#else
> +#define __math_with_errno(x, e) (x)
> +#define __math_with_errnof(x, e) (x)
> +#endif
> +
> +HIDDEN double
> +__math_xflow (uint32_t sign, double y);
> +
> +HIDDEN float
> +__math_xflowf (uint32_t sign, float y);
> +
> #endif
> diff --git a/newlib/libm/common/math_err_check_oflow.c
> b/newlib/libm/common/math_err_check_oflow.c
> new file mode 100644
> index 000000000..27afe41cb
> --- /dev/null
> +++ b/newlib/libm/common/math_err_check_oflow.c
> @@ -0,0 +1,37 @@
> +/* Double-precision math error handling.
> + Copyright (c) 2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "math_config.h"
> +
> +/* Check result and set errno if necessary. */
> +
> +HIDDEN double
> +__math_check_oflow (double y)
> +{
> + return isinf (y) ? __math_with_errno (y, ERANGE) : y;
> +}
> diff --git a/newlib/libm/common/math_err_check_uflow.c
> b/newlib/libm/common/math_err_check_uflow.c
> new file mode 100644
> index 000000000..c61d12f4a
> --- /dev/null
> +++ b/newlib/libm/common/math_err_check_uflow.c
> @@ -0,0 +1,37 @@
> +/* Double-precision math error handling.
> + Copyright (c) 2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "math_config.h"
> +
> +/* Check result and set errno if necessary. */
> +
> +HIDDEN double
> +__math_check_uflow (double y)
> +{
> + return y == 0.0 ? __math_with_errno (y, ERANGE) : y;
> +}
> diff --git a/newlib/libm/common/math_err_divzero.c
> b/newlib/libm/common/math_err_divzero.c
> new file mode 100644
> index 000000000..6ca5f845d
> --- /dev/null
> +++ b/newlib/libm/common/math_err_divzero.c
> @@ -0,0 +1,36 @@
> +/* Double-precision math error handling.
> + Copyright (c) 2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "math_config.h"
> +
> +HIDDEN double
> +__math_divzero (uint32_t sign)
> +{
> + double y = opt_barrier_double (sign ? -1.0 : 1.0) / 0.0;
> + return __math_with_errno (y, ERANGE);
> +}
> diff --git a/newlib/libm/common/math_err_invalid.c
> b/newlib/libm/common/math_err_invalid.c
> new file mode 100644
> index 000000000..2f2dc299f
> --- /dev/null
> +++ b/newlib/libm/common/math_err_invalid.c
> @@ -0,0 +1,36 @@
> +/* Double-precision math error handling.
> + Copyright (c) 2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "math_config.h"
> +
> +HIDDEN double
> +__math_invalid (double x)
> +{
> + double y = (x - x) / (x - x);
> + return isnan (x) ? y : __math_with_errno (y, EDOM);
> +}
> diff --git a/newlib/libm/common/math_err.c
> b/newlib/libm/common/math_err_may_uflow.c
> similarity index 60%
> rename from newlib/libm/common/math_err.c
> rename to newlib/libm/common/math_err_may_uflow.c
> index 6eb77c8da..1eaefcdba 100644
> --- a/newlib/libm/common/math_err.c
> +++ b/newlib/libm/common/math_err_may_uflow.c
> @@ -28,74 +28,12 @@
>
> #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 double
> -with_errno (double y, int e)
> -{
> - errno = e;
> - return y;
> -}
> -#else
> -#define with_errno(x, e) (x)
> -#endif
> -
> -/* NOINLINE reduces code size. */
> -NOINLINE static double
> -xflow (uint32_t sign, double y)
> -{
> - y = opt_barrier_double (sign ? -y : y) * y;
> - return with_errno (y, ERANGE);
> -}
> -
> -HIDDEN double
> -__math_uflow (uint32_t sign)
> -{
> - return xflow (sign, 0x1p-767);
> -}
> -
> #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 double
> __math_may_uflow (uint32_t sign)
> {
> - return xflow (sign, 0x1.8p-538);
> + return __math_xflow (sign, 0x1.8p-538);
> }
> #endif
> -
> -HIDDEN double
> -__math_oflow (uint32_t sign)
> -{
> - return xflow (sign, 0x1p769);
> -}
> -
> -HIDDEN double
> -__math_divzero (uint32_t sign)
> -{
> - double y = opt_barrier_double (sign ? -1.0 : 1.0) / 0.0;
> - return with_errno (y, ERANGE);
> -}
> -
> -HIDDEN double
> -__math_invalid (double x)
> -{
> - double y = (x - x) / (x - x);
> - return isnan (x) ? y : with_errno (y, EDOM);
> -}
> -
> -/* Check result and set errno if necessary. */
> -
> -HIDDEN double
> -__math_check_uflow (double y)
> -{
> - return y == 0.0 ? with_errno (y, ERANGE) : y;
> -}
> -
> -HIDDEN double
> -__math_check_oflow (double y)
> -{
> - return isinf (y) ? with_errno (y, ERANGE) : y;
> -}
> diff --git a/newlib/libm/common/math_err_oflow.c
> b/newlib/libm/common/math_err_oflow.c
> new file mode 100644
> index 000000000..667e9a0e8
> --- /dev/null
> +++ b/newlib/libm/common/math_err_oflow.c
> @@ -0,0 +1,35 @@
> +/* Double-precision math error handling.
> + Copyright (c) 2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "math_config.h"
> +
> +HIDDEN double
> +__math_oflow (uint32_t sign)
> +{
> + return __math_xflow (sign, 0x1p769);
> +}
> diff --git a/newlib/libm/common/math_err_uflow.c
> b/newlib/libm/common/math_err_uflow.c
> new file mode 100644
> index 000000000..7c4fe5131
> --- /dev/null
> +++ b/newlib/libm/common/math_err_uflow.c
> @@ -0,0 +1,35 @@
> +/* Double-precision math error handling.
> + Copyright (c) 2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "math_config.h"
> +
> +HIDDEN double
> +__math_uflow (uint32_t sign)
> +{
> + return __math_xflow (sign, 0x1p-767);
> +}
> diff --git a/newlib/libm/common/math_err_with_errno.c
> b/newlib/libm/common/math_err_with_errno.c
> new file mode 100644
> index 000000000..fa5834880
> --- /dev/null
> +++ b/newlib/libm/common/math_err_with_errno.c
> @@ -0,0 +1,41 @@
> +/* Double-precision math error handling.
> + Copyright (c) 2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#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 HIDDEN double
> +__math_with_errno (double y, int e)
> +{
> + errno = e;
> + return y;
> +}
> +#endif
> diff --git a/newlib/libm/common/math_err_xflow.c
> b/newlib/libm/common/math_err_xflow.c
> new file mode 100644
> index 000000000..50cbdf5e1
> --- /dev/null
> +++ b/newlib/libm/common/math_err_xflow.c
> @@ -0,0 +1,36 @@
> +/* Double-precision math error handling.
> + Copyright (c) 2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "math_config.h"
> +
> +HIDDEN double
> +__math_xflow (uint32_t sign, double y)
> +{
> + y = opt_barrier_double (sign ? -y : y) * y;
> + return __math_with_errno (y, ERANGE);
> +}
> diff --git a/newlib/libm/common/math_errf_divzerof.c
> b/newlib/libm/common/math_errf_divzerof.c
> new file mode 100644
> index 000000000..c5f56367d
> --- /dev/null
> +++ b/newlib/libm/common/math_errf_divzerof.c
> @@ -0,0 +1,39 @@
> +/* Single-precision math error handling.
> + Copyright (c) 2017-2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "fdlibm.h"
> +#include "math_config.h"
> +
> +#if !__OBSOLETE_MATH
> +HIDDEN float
> +__math_divzerof (uint32_t sign)
> +{
> + float y = 0;
> + return __math_with_errnof ((sign ? -1 : 1) / y, ERANGE);
> +}
> +#endif
> diff --git a/newlib/libm/common/math_errf_invalidf.c
> b/newlib/libm/common/math_errf_invalidf.c
> new file mode 100644
> index 000000000..cf1b70994
> --- /dev/null
> +++ b/newlib/libm/common/math_errf_invalidf.c
> @@ -0,0 +1,39 @@
> +/* Single-precision math error handling.
> + Copyright (c) 2017-2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "fdlibm.h"
> +#include "math_config.h"
> +
> +#if !__OBSOLETE_MATH
> +HIDDEN float
> +__math_invalidf (float x)
> +{
> + float y = (x - x) / (x - x);
> + return isnan (x) ? y : __math_with_errnof (y, EDOM);
> +}
> +#endif /* !__OBSOLETE_MATH */
> diff --git a/newlib/libm/common/math_errf.c
> b/newlib/libm/common/math_errf_may_uflowf.c
> similarity index 66%
> rename from newlib/libm/common/math_errf.c
> rename to newlib/libm/common/math_errf_may_uflowf.c
> index 762fc2799..b863c805c 100644
> --- a/newlib/libm/common/math_errf.c
> +++ b/newlib/libm/common/math_errf_may_uflowf.c
> @@ -29,64 +29,14 @@
> #include "fdlibm.h"
> #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 prevents fenv semantics breaking optimizations. */
> -NOINLINE static float
> -xflowf (uint32_t sign, float y)
> -{
> - y = (sign ? -y : y) * y;
> - return with_errnof (y, ERANGE);
> -}
> -
> #if !__OBSOLETE_MATH
> -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);
> + return __math_xflowf (sign, 0x1.4p-75f);
> }
> #endif
> #endif /* !__OBSOLETE_MATH */
> -
> -HIDDEN float
> -__math_oflowf (uint32_t sign)
> -{
> - return xflowf (sign, 0x1p97f);
> -}
> -
> -#if !__OBSOLETE_MATH
> -HIDDEN float
> -__math_divzerof (uint32_t sign)
> -{
> - float y = 0;
> - return with_errnof ((sign ? -1 : 1) / y, ERANGE);
> -}
> -
> -HIDDEN float
> -__math_invalidf (float x)
> -{
> - float y = (x - x) / (x - x);
> - return isnan (x) ? y : with_errnof (y, EDOM);
> -}
> -#endif /* !__OBSOLETE_MATH */
> diff --git a/newlib/libm/common/math_errf_oflowf.c
> b/newlib/libm/common/math_errf_oflowf.c
> new file mode 100644
> index 000000000..71360fbf6
> --- /dev/null
> +++ b/newlib/libm/common/math_errf_oflowf.c
> @@ -0,0 +1,36 @@
> +/* Single-precision math error handling.
> + Copyright (c) 2017-2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "fdlibm.h"
> +#include "math_config.h"
> +
> +HIDDEN float
> +__math_oflowf (uint32_t sign)
> +{
> + return __math_xflowf (sign, 0x1p97f);
> +}
> diff --git a/newlib/libm/common/math_errf_uflowf.c
> b/newlib/libm/common/math_errf_uflowf.c
> new file mode 100644
> index 000000000..c4876e55d
> --- /dev/null
> +++ b/newlib/libm/common/math_errf_uflowf.c
> @@ -0,0 +1,38 @@
> +/* Single-precision math error handling.
> + Copyright (c) 2017-2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "fdlibm.h"
> +#include "math_config.h"
> +
> +#if !__OBSOLETE_MATH
> +HIDDEN float
> +__math_uflowf (uint32_t sign)
> +{
> + return __math_xflowf (sign, 0x1p-95f);
> +}
> +#endif
> diff --git a/newlib/libm/common/math_errf_with_errnof.c
> b/newlib/libm/common/math_errf_with_errnof.c
> new file mode 100644
> index 000000000..9c0fa06cf
> --- /dev/null
> +++ b/newlib/libm/common/math_errf_with_errnof.c
> @@ -0,0 +1,41 @@
> +/* Single-precision math error handling.
> + Copyright (c) 2017-2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "fdlibm.h"
> +#include "math_config.h"
> +
> +#if WANT_ERRNO
> +#include <errno.h>
> +HIDDEN float
> +__math_with_errnof (float y, int e)
> +{
> + errno = e;
> + return y;
> +}
> +#endif
> +
> diff --git a/newlib/libm/common/math_errf_xflowf.c
> b/newlib/libm/common/math_errf_xflowf.c
> new file mode 100644
> index 000000000..88d593adb
> --- /dev/null
> +++ b/newlib/libm/common/math_errf_xflowf.c
> @@ -0,0 +1,38 @@
> +/* Single-precision math error handling.
> + Copyright (c) 2017-2018 Arm Ltd. All rights reserved.
> +
> + SPDX-License-Identifier: BSD-3-Clause
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions
> + are met:
> + 1. Redistributions of source code must retain the above copyright
> + notice, this list of conditions and the following disclaimer.
> + 2. Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + 3. The name of the company may not be used to endorse or promote
> + products derived from this software without specific prior written
> + permission.
> +
> + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR
> IMPLIED
> + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> LIMITED
> + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
> +
> +#include "fdlibm.h"
> +#include "math_config.h"
> +
> +/* NOINLINE prevents fenv semantics breaking optimizations. */
> +HIDDEN float
> +__math_xflowf (uint32_t sign, float y)
> +{
> + y = (sign ? -y : y) * y;
> + return __math_with_errnof (y, ERANGE);
> +}
> --
> 2.23.0.rc1
>
>
More information about the Newlib
mailing list