From eba03c25905406b0731d46817d996d4b7691df68 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Jan 2017 09:37:33 -0600 Subject: [PATCH] Math library: Leverage optimized ARM functions from BSD license ARM file. --- arch/arm/src/armv7-m/up_initialstate.c | 12 ---- libc/Kconfig | 1 + libc/Makefile | 3 +- libc/machine/Kconfig | 72 +++++++++++++++++++++++ libc/machine/Make.defs | 40 +++++++++++++ libc/machine/arm/Make.defs | 53 +++++++++++++++++ libc/machine/arm/lib_ceil.c | 53 +++++++++++++++++ libc/machine/arm/lib_ceilf.c | 53 +++++++++++++++++ libc/machine/arm/lib_floor.c | 53 +++++++++++++++++ libc/machine/arm/lib_floorf.c | 53 +++++++++++++++++ libc/machine/arm/lib_nearbyint.c | 53 +++++++++++++++++ libc/machine/arm/lib_nearbyintf.c | 53 +++++++++++++++++ libc/machine/arm/lib_rint.c | 53 +++++++++++++++++ libc/machine/arm/lib_rintf.c | 53 +++++++++++++++++ libc/machine/arm/lib_round.c | 53 +++++++++++++++++ libc/machine/arm/lib_roundf.c | 53 +++++++++++++++++ libc/machine/arm/lib_trunc.c | 53 +++++++++++++++++ libc/machine/arm/lib_truncf.c | 53 +++++++++++++++++ libc/math/Make.defs | 80 ++++++++++++++++++++------ 19 files changed, 866 insertions(+), 31 deletions(-) create mode 100644 libc/machine/Kconfig create mode 100644 libc/machine/Make.defs create mode 100644 libc/machine/arm/Make.defs create mode 100644 libc/machine/arm/lib_ceil.c create mode 100644 libc/machine/arm/lib_ceilf.c create mode 100644 libc/machine/arm/lib_floor.c create mode 100644 libc/machine/arm/lib_floorf.c create mode 100644 libc/machine/arm/lib_nearbyint.c create mode 100644 libc/machine/arm/lib_nearbyintf.c create mode 100644 libc/machine/arm/lib_rint.c create mode 100644 libc/machine/arm/lib_rintf.c create mode 100644 libc/machine/arm/lib_round.c create mode 100644 libc/machine/arm/lib_roundf.c create mode 100644 libc/machine/arm/lib_trunc.c create mode 100644 libc/machine/arm/lib_truncf.c diff --git a/arch/arm/src/armv7-m/up_initialstate.c b/arch/arm/src/armv7-m/up_initialstate.c index 7cf6816c218..37cb86cb464 100644 --- a/arch/arm/src/armv7-m/up_initialstate.c +++ b/arch/arm/src/armv7-m/up_initialstate.c @@ -51,18 +51,6 @@ #include "psr.h" #include "exc_return.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libc/Kconfig b/libc/Kconfig index a8d40fed543..0eb36f38bf4 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -33,6 +33,7 @@ config LIB_HOMEDIR The home directory to use with operations like such as 'cd ~' source libc/math/Kconfig +source libc/machine/Kconfig config NOPRINTF_FIELDWIDTH bool "Disable sprintf support fieldwidth" diff --git a/libc/Makefile b/libc/Makefile index 81a1994007b..11b255333b3 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -1,7 +1,7 @@ ############################################################################ # libc/Makefile # -# Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2014, 2016-2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -68,6 +68,7 @@ include fixedmath/Make.defs include hex2bin/Make.defs include libgen/Make.defs include locale/Make.defs +include machine/Make.defs include math/Make.defs include misc/Make.defs include net/Make.defs diff --git a/libc/machine/Kconfig b/libc/machine/Kconfig new file mode 100644 index 00000000000..d6bc6febb89 --- /dev/null +++ b/libc/machine/Kconfig @@ -0,0 +1,72 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config LIBM_ARCH_CEIL + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_FLOOR + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_NEARBYINT + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_RINT + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_ROUND + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_TRUNC + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_CEILF + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_FLOORF + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_NEARBYINTF + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_RINTF + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_ROUNDF + default n + depends on LIBC_ARCHOPT + +config LIBM_ARCH_TRUNCF + default n + depends on LIBC_ARCHOPT + +config LIBC_ARCHOPT + bool "Architecture specific optimizations" + default n + select LIBM_ARCH_CEIL if CONFIG_ARCH_DPFPU + select LIBM_ARCH_FLOOR if CONFIG_ARCH_DPFPU + select LIBM_ARCH_NEARBYINT if CONFIG_ARCH_DPFPU + select LIBM_ARCH_RINT if CONFIG_ARCH_DPFPU + select LIBM_ARCH_ROUND if CONFIG_ARCH_DPFPU + select LIBM_ARCH_TRUNC if CONFIG_ARCH_DPFPU + select LIBM_ARCH_CEILF if CONFIG_ARCH_FPU + select LIBM_ARCH_FLOORF if CONFIG_ARCH_FPU + select LIBM_ARCH_NEARBYINTF if CONFIG_ARCH_FPU + select LIBM_ARCH_RINTF if CONFIG_ARCH_FPU + select LIBM_ARCH_ROUNDF if CONFIG_ARCH_FPU + select LIBM_ARCH_TRUNCF if CONFIG_ARCH_FPU + depends on ARM && LIBM + ---help--- + Enable architecture specific optimizations. Currently only + available for use with ARM and only for the NuttX math library. diff --git a/libc/machine/Make.defs b/libc/machine/Make.defs new file mode 100644 index 00000000000..1149a8da3ae --- /dev/null +++ b/libc/machine/Make.defs @@ -0,0 +1,40 @@ +############################################################################ +# libc/machine/Make.defs +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "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 THE +# COPYRIGHT OWNER OR CONTRIBUTORS 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. +# +############################################################################ + +ifeq ($(CONFIG_LIBC_ARCHOPT),y) +ifeq ($(CONFIG_ARCH_ARM),y) +include ${TOPDIR}/libc/machine/arm/Make.defs +endif +endif diff --git a/libc/machine/arm/Make.defs b/libc/machine/arm/Make.defs new file mode 100644 index 00000000000..127bfba153e --- /dev/null +++ b/libc/machine/arm/Make.defs @@ -0,0 +1,53 @@ +############################################################################ +# libc/machine/arm/Make.defs +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "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 THE +# COPYRIGHT OWNER OR CONTRIBUTORS 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. +# +############################################################################ + +ifeq ($(CONFIG_LIBM),y) +ifeq ($(CONFIG_ARCH_FPU),y) + +CSRCS += lib_ceilf.c lib_floorf.c lib_nearbyintf.c lib_rintf.c +CSRCS += lib_roundf.c lib_truncf.c + +ifeq ($(CONFIG_ARCH_DPFPU),y) + +CSRCS += lib_ceil.c lib_floor.c lib_nearbyint.c lib_rint.c lib_round.c +CSRCS += lib_trunc.c + +endif # CONFIG_ARCH_DPFPU + +DEPPATH += --dep-path machine/arm +VPATH += :machine/arm + +endif # CONFIG_ARCH_FPU +endif # CONFIG_LIBM diff --git a/libc/machine/arm/lib_ceil.c b/libc/machine/arm/lib_ceil.c new file mode 100644 index 00000000000..25d93a877b2 --- /dev/null +++ b/libc/machine/arm/lib_ceil.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_ceil.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && (__ARM_FP & 0x8) && !defined (__SOFTFP__) + +double ceil(double x) +{ + double result; + asm volatile ( "vrintp.f64\t%P0, %P1" : "=w" (result) : "w" (x) ); + return result; +} + +#else +# warning ceil() not built +#endif diff --git a/libc/machine/arm/lib_ceilf.c b/libc/machine/arm/lib_ceilf.c new file mode 100644 index 00000000000..3f80b07bff7 --- /dev/null +++ b/libc/machine/arm/lib_ceilf.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_ceilf.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && !defined (__SOFTFP__) + +float ceilf(float x) +{ + float result; + asm volatile ( "vrintp.f32\t%0, %1" : "=t" (result) : "t" (x) ); + return result; +} + +#else +# warning ceilf() not built +#endif diff --git a/libc/machine/arm/lib_floor.c b/libc/machine/arm/lib_floor.c new file mode 100644 index 00000000000..8957aeb80c9 --- /dev/null +++ b/libc/machine/arm/lib_floor.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_floor.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && (__ARM_FP & 0x8) && !defined (__SOFTFP__) + +double floor(double x) +{ + double result; + asm volatile ("vrintm.f64\t%P0, %P1" : "=w" (result) : "w" (x)); + return result; +} + +#else +# warning floor() not built +#endif diff --git a/libc/machine/arm/lib_floorf.c b/libc/machine/arm/lib_floorf.c new file mode 100644 index 00000000000..4e7112e1488 --- /dev/null +++ b/libc/machine/arm/lib_floorf.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_floorf.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && !defined (__SOFTFP__) + +float floorf(float x) +{ + float result; + asm volatile ( "vrintm.f32\t%0, %1" : "=t" (result) : "t" (x) ); + return result; +} + +#else +# warning floorf() not built +#endif diff --git a/libc/machine/arm/lib_nearbyint.c b/libc/machine/arm/lib_nearbyint.c new file mode 100644 index 00000000000..2718ce5f615 --- /dev/null +++ b/libc/machine/arm/lib_nearbyint.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_nearbyint.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && (__ARM_FP & 0x8) && !defined (__SOFTFP__) + +double nearbyint(double x) +{ + double result; + asm volatile ("vrintr.f64\t%P0, %P1" : "=w" (result) : "w" (x)); + return result; +} + +#else +# warning nearbyint() not built +#endif diff --git a/libc/machine/arm/lib_nearbyintf.c b/libc/machine/arm/lib_nearbyintf.c new file mode 100644 index 00000000000..81158dc4c28 --- /dev/null +++ b/libc/machine/arm/lib_nearbyintf.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_nearbyintf.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && !defined (__SOFTFP__) + +float nearbyintf(float x) +{ + float result; + asm volatile ("vrintr.f32\t%0, %1" : "=t" (result) : "t" (x)); + return result; +} + +#else +# warning nearbyintf() not built +#endif diff --git a/libc/machine/arm/lib_rint.c b/libc/machine/arm/lib_rint.c new file mode 100644 index 00000000000..d085486cc0e --- /dev/null +++ b/libc/machine/arm/lib_rint.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_rint.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && (__ARM_FP & 0x8) && !defined (__SOFTFP__) + +double rint(double x) +{ + double result; + asm volatile ("vrintx.f64\t%P0, %P1" : "=w" (result) : "w" (x)); + return result; +} + +#else +# warning rint() not built +#endif diff --git a/libc/machine/arm/lib_rintf.c b/libc/machine/arm/lib_rintf.c new file mode 100644 index 00000000000..f57cddd5dc4 --- /dev/null +++ b/libc/machine/arm/lib_rintf.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_rintf.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && !defined (__SOFTFP__) + +float rintf(float x) +{ + float result; + asm volatile ("vrintx.f32\t%0, %1" : "=t" (result) : "t" (x)); + return result; +} + +#else +# warning rintf() not built +#endif diff --git a/libc/machine/arm/lib_round.c b/libc/machine/arm/lib_round.c new file mode 100644 index 00000000000..df371770063 --- /dev/null +++ b/libc/machine/arm/lib_round.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_round.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && (__ARM_FP & 0x8) && !defined (__SOFTFP__) + +double round(double x) +{ + double result; + asm volatile ("vrinta.f64\t%P0, %P1" : "=w" (result) : "w" (x)); + return result; +} + +#else +# warning round() not built +#endif diff --git a/libc/machine/arm/lib_roundf.c b/libc/machine/arm/lib_roundf.c new file mode 100644 index 00000000000..24db1080579 --- /dev/null +++ b/libc/machine/arm/lib_roundf.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_roundf.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && !defined (__SOFTFP__) + +float roundf(float x) +{ + float result; + asm volatile ("vrinta.f32\t%0, %1" : "=t" (result) : "t" (x)); + return result; +} + +#else +# warning roundf() not built +#endif diff --git a/libc/machine/arm/lib_trunc.c b/libc/machine/arm/lib_trunc.c new file mode 100644 index 00000000000..d7c6369adf3 --- /dev/null +++ b/libc/machine/arm/lib_trunc.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_trunc.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && (__ARM_FP & 0x8) && !defined (__SOFTFP__) + +double trunc(double x) +{ + double result; + asm volatile ("vrintz.f64\t%P0, %P1" : "=w" (result) : "w" (x)); + return result; +} + +#else +# warning trunc() not built +#endif diff --git a/libc/machine/arm/lib_truncf.c b/libc/machine/arm/lib_truncf.c new file mode 100644 index 00000000000..a416bb8f4c6 --- /dev/null +++ b/libc/machine/arm/lib_truncf.c @@ -0,0 +1,53 @@ +/**************************************************************************** + * libc/machine/arm/lib_truncf.c + * + * Copyright (c) 2011, 2012 ARM Ltd. All rights reserved. + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#if __ARM_ARCH >= 8 && !defined (__SOFTFP__) + +float truncf(float x) +{ + float result; + asm volatile ("vrintz.f32\t%0, %1" : "=t" (result) : "t" (x)); + return result; +} + +#else +# warning truncf() not built +#endif diff --git a/libc/math/Make.defs b/libc/math/Make.defs index a2acc7a93a0..7ead14882a3 100644 --- a/libc/math/Make.defs +++ b/libc/math/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # libc/math/Make.defs # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,30 +37,74 @@ ifeq ($(CONFIG_LIBM),y) # Add the floating point math C files to the build -CSRCS += lib_acosf.c lib_asinf.c lib_atan2f.c lib_atanf.c lib_ceilf.c lib_cosf.c -CSRCS += lib_coshf.c lib_expf.c lib_fabsf.c lib_floorf.c lib_fmodf.c lib_frexpf.c -CSRCS += lib_ldexpf.c lib_logf.c lib_log10f.c lib_log2f.c lib_modff.c lib_powf.c -CSRCS += lib_rintf.c lib_roundf.c lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c -CSRCS += lib_tanhf.c lib_asinhf.c lib_acoshf.c lib_atanhf.c lib_erff.c lib_copysignf.c -CSRCS += lib_truncf.c +CSRCS += lib_acosf.c lib_asinf.c lib_atan2f.c lib_atanf.c lib_cosf.c +CSRCS += lib_coshf.c lib_expf.c lib_fabsf.c lib_fmodf.c lib_frexpf.c +CSRCS += lib_ldexpf.c lib_logf.c lib_log10f.c lib_log2f.c lib_modff.c +CSRCS += lib_powf.c lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c +CSRCS += lib_tanhf.c lib_asinhf.c lib_acoshf.c lib_atanhf.c lib_erff.c +CSRCS += lib_copysignf.c -CSRCS += lib_acos.c lib_asin.c lib_atan.c lib_atan2.c lib_ceil.c lib_cos.c -CSRCS += lib_cosh.c lib_exp.c lib_fabs.c lib_floor.c lib_fmod.c lib_frexp.c -CSRCS += lib_ldexp.c lib_log.c lib_log10.c lib_log2.c lib_modf.c lib_pow.c -CSRCS += lib_rint.c lib_round.c lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c -CSRCS += lib_tanh.c lib_asinh.c lib_acosh.c lib_atanh.c lib_erf.c lib_copysign.c -CSRCS += lib_trunc.c +CSRCS += lib_acos.c lib_asin.c lib_atan.c lib_atan2.c lib_cos.c +CSRCS += lib_cosh.c lib_exp.c lib_fabs.c lib_fmod.c lib_frexp.c +CSRCS += lib_ldexp.c lib_log.c lib_log10.c lib_log2.c lib_modf.c +CSRCS += lib_pow.c lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c +CSRCS += lib_tanh.c lib_asinh.c lib_acosh.c lib_atanh.c lib_erf.c +CSRCS += lib_copysign.c -CSRCS += lib_acosl.c lib_asinl.c lib_atan2l.c lib_atanl.c lib_ceill.c lib_cosl.c -CSRCS += lib_coshl.c lib_expl.c lib_fabsl.c lib_floorl.c lib_fmodl.c lib_frexpl.c -CSRCS += lib_ldexpl.c lib_logl.c lib_log10l.c lib_log2l.c lib_modfl.c lib_powl.c -CSRCS += lib_rintl.c lib_roundl.c lib_sinl.c lib_sinhl.c lib_sqrtl.c lib_tanl.c -CSRCS += lib_tanhl.c lib_asinhl.c lib_acoshl.c lib_atanhl.c lib_erfl.c lib_copysignl.c +CSRCS += lib_acosl.c lib_asinl.c lib_atan2l.c lib_atanl.c lib_ceill.c +CSRCS += lib_cosl.c lib_coshl.c lib_expl.c lib_fabsl.c lib_floorl.c +CSRCS += lib_fmodl.c lib_frexpl.c lib_ldexpl.c lib_logl.c lib_log10l.c +CSRCS += lib_log2l.c lib_modfl.c lib_powl.c lib_rintl.c lib_roundl.c +CSRCS += lib_sinl.c lib_sinhl.c lib_sqrtl.c lib_tanl.c lib_tanhl.c +CSRCS += lib_asinhl.c lib_acoshl.c lib_atanhl.c lib_erfl.c lib_copysignl.c CSRCS += lib_truncl.c CSRCS += lib_libexpi.c lib_libsqrtapprox.c CSRCS += lib_libexpif.c +# Use the C versions of some functions only if architecture specific +# optimized versions are not provided. + +ifneq ($(LIBM_ARCH_CEIL),y) +CSRCS += lib_ceil.c +endif + +ifneq ($(LIBM_ARCH_FLOOR),y) +CSRCS += lib_floor.c +endif + +ifneq ($(LIBM_ARCH_RINT),y) +CSRCS += lib_rint.c +endif + +ifneq ($(LIBM_ARCH_ROUND),y) +CSRCS += lib_round.c +endif + +ifneq ($(LIBM_ARCH_TRUNC),y) +CSRCS += lib_trunc.c +endif + +ifneq ($(LIBM_ARCH_CEILF),y) +CSRCS += lib_ceilf.c +endif + +ifneq ($(LIBM_ARCH_FLOORF),y) +CSRCS += lib_floorf.c +endif + +ifneq ($(LIBM_ARCH_RINTF),y) +CSRCS += lib_rintf.c +endif + +ifneq ($(LIBM_ARCH_ROUNDF),y) +CSRCS += lib_roundf.c +endif + +ifneq ($(LIBM_ARCH_TRUNCF),y) +CSRCS += lib_truncf.c +endif + # Add the floating point math directory to the build DEPPATH += --dep-path math