Math library: Leverage optimized ARM functions from BSD license ARM file.

This commit is contained in:
Gregory Nutt 2017-01-19 09:37:33 -06:00
parent fcc8444ae0
commit eba03c2590
19 changed files with 866 additions and 31 deletions

View File

@ -51,18 +51,6 @@
#include "psr.h"
#include "exc_return.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/

View File

@ -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"

View File

@ -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 <gnutt@nuttx.org>
#
# 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

72
libc/machine/Kconfig Normal file
View File

@ -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.

40
libc/machine/Make.defs Normal file
View File

@ -0,0 +1,40 @@
############################################################################
# libc/machine/Make.defs
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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

View File

@ -0,0 +1,53 @@
############################################################################
# libc/machine/arm/Make.defs
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <math.h>
/****************************************************************************
* 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

View File

@ -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 <gnutt@nuttx.org>
#
# 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