Re: arm64: userland pieces (libm)
> If Theo and Philip agree, I think you should just move ahead and > import new bits and obvious makefile changes straightaway. It is much > easier to have it in the tree such that we can produce diffs for any > mistakes that are made. Yeah, just start dribbling them in.
Re: arm64: userland pieces (libm)
> Date: Wed, 11 Jan 2017 14:12:59 +0100 > From: Patrick Wildt> > Hi, > > I'd like to start importing the userland pieces, piece by piece. This > diff implements support for aarch64 in libm. It's based on the FreeBSD > header, modified to look and feel more like our code. > > ok? If Theo and Philip agree, I think you should just move ahead and import new bits and obvious makefile changes straightaway. It is much easier to have it in the tree such that we can produce diffs for any mistakes that are made. Cheers, Mark > diff --git a/lib/libm/Makefile b/lib/libm/Makefile > index 3854bb395fe..3d063929d0a 100644 > --- a/lib/libm/Makefile > +++ b/lib/libm/Makefile > @@ -48,6 +48,8 @@ ARCH_SRCS = e_sqrt.c e_sqrtf.c e_remainder.c e_remainderf.c > \ > .elif (${MACHINE_ARCH} == "sh") > .PATH: ${.CURDIR}/arch/sh > ARCH_SRCS = e_sqrt.c e_sqrtf.c s_fabsf.c > +.elif (${MACHINE_ARCH} == "aarch64") > +.PATH: ${.CURDIR}/arch/aarch64 > .elif (${MACHINE_ARCH} == "arm") > .PATH: ${.CURDIR}/arch/arm > .elif (${MACHINE_ARCH} == "m88k") > @@ -134,7 +136,8 @@ SRCS= ${COMMON_SRCS} ${PURE_SRCS} > CPPFLAGS+= -I${.CURDIR}/src -I${.CURDIR}/src/ld80 > SRCS+= ${LONG_SRCS} > .endif > -.if (${MACHINE_CPU} == "mips64") || (${MACHINE_ARCH} == "sparc64") > +.if (${MACHINE_CPU} == "mips64") || (${MACHINE_ARCH} == "sparc64") || \ > +(${MACHINE_ARCH} == "aarch64") > .PATH: ${.CURDIR}/src/ld128 > CPPFLAGS+= -I${.CURDIR}/src -I${.CURDIR}/src/ld128 > SRCS+= ${LONG_SRCS} > diff --git a/lib/libm/arch/aarch64/fenv.c b/lib/libm/arch/aarch64/fenv.c > new file mode 100644 > index 000..f186b3d260c > --- /dev/null > +++ b/lib/libm/arch/aarch64/fenv.c > @@ -0,0 +1,284 @@ > +/* $OpenBSD$ */ > +/*- > + * Copyright (c) 2004-2005 David Schultz > + * 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. > + * > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. > + * > + * $FreeBSD: head/lib/msun/aarch64/fenv.h 280857 2015-03-30 16:42:08Z emaste > $ > + */ > + > +#include > +#include > + > +/* We need to be able to map status flag positions to mask flag positions */ > +#define _FPUSW_SHIFT8 > +#define _ENABLE_MASK(FE_ALL_EXCEPT << _FPUSW_SHIFT) > + > +#define __mrs_fpcr(r) __asm __volatile("mrs %x0, fpcr" : "=r" (r)) > +#define __msr_fpcr(r) __asm __volatile("msr fpcr, %x0" : : "r" (r)) > + > +#define __mrs_fpsr(r) __asm __volatile("mrs %x0, fpsr" : "=r" (r)) > +#define __msr_fpsr(r) __asm __volatile("msr fpsr, %x0" : : "r" (r)) > + > +/* > + * The following constant represents the default floating-point environment > + * (that is, the one installed at program startup) and has type pointer to > + * const-qualified fenv_t. > + * > + * It can be used as an argument to the functions within the header > + * that manage the floating-point environment, namely fesetenv() and > + * feupdateenv(). > + */ > +fenv_t __fe_dfl_env = 0; > + > +/* > + * The feclearexcept() function clears the supported floating-point > exceptions > + * represented by `excepts'. > + */ > +int > +feclearexcept(int excepts) > +{ > + fexcept_t r; > + > + __mrs_fpsr(r); > + r &= ~excepts; > + __msr_fpsr(r); > + return (0); > +} > +DEF_STD(feclearexcept); > + > +/* > + * The fegetexceptflag() function stores an implementation-defined > + * representation of the states of the floating-point status flags indicated > by > + * the argument excepts in the object pointed to by the argument flagp. > + */ > +int > +fegetexceptflag(fexcept_t *flagp, int excepts) > +{ > + fexcept_t r; > + > + __mrs_fpsr(r); > + *flagp = r & excepts; > + return (0);
arm64: userland pieces (libm)
Hi, I'd like to start importing the userland pieces, piece by piece. This diff implements support for aarch64 in libm. It's based on the FreeBSD header, modified to look and feel more like our code. ok? Patrick diff --git a/lib/libm/Makefile b/lib/libm/Makefile index 3854bb395fe..3d063929d0a 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -48,6 +48,8 @@ ARCH_SRCS = e_sqrt.c e_sqrtf.c e_remainder.c e_remainderf.c \ .elif (${MACHINE_ARCH} == "sh") .PATH: ${.CURDIR}/arch/sh ARCH_SRCS = e_sqrt.c e_sqrtf.c s_fabsf.c +.elif (${MACHINE_ARCH} == "aarch64") +.PATH: ${.CURDIR}/arch/aarch64 .elif (${MACHINE_ARCH} == "arm") .PATH: ${.CURDIR}/arch/arm .elif (${MACHINE_ARCH} == "m88k") @@ -134,7 +136,8 @@ SRCS= ${COMMON_SRCS} ${PURE_SRCS} CPPFLAGS+= -I${.CURDIR}/src -I${.CURDIR}/src/ld80 SRCS+= ${LONG_SRCS} .endif -.if (${MACHINE_CPU} == "mips64") || (${MACHINE_ARCH} == "sparc64") +.if (${MACHINE_CPU} == "mips64") || (${MACHINE_ARCH} == "sparc64") || \ +(${MACHINE_ARCH} == "aarch64") .PATH: ${.CURDIR}/src/ld128 CPPFLAGS+= -I${.CURDIR}/src -I${.CURDIR}/src/ld128 SRCS+= ${LONG_SRCS} diff --git a/lib/libm/arch/aarch64/fenv.c b/lib/libm/arch/aarch64/fenv.c new file mode 100644 index 000..f186b3d260c --- /dev/null +++ b/lib/libm/arch/aarch64/fenv.c @@ -0,0 +1,284 @@ +/* $OpenBSD$ */ +/*- + * Copyright (c) 2004-2005 David Schultz+ * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: head/lib/msun/aarch64/fenv.h 280857 2015-03-30 16:42:08Z emaste $ + */ + +#include +#include + +/* We need to be able to map status flag positions to mask flag positions */ +#define_FPUSW_SHIFT8 +#define_ENABLE_MASK(FE_ALL_EXCEPT << _FPUSW_SHIFT) + +#define__mrs_fpcr(r) __asm __volatile("mrs %x0, fpcr" : "=r" (r)) +#define__msr_fpcr(r) __asm __volatile("msr fpcr, %x0" : : "r" (r)) + +#define__mrs_fpsr(r) __asm __volatile("mrs %x0, fpsr" : "=r" (r)) +#define__msr_fpsr(r) __asm __volatile("msr fpsr, %x0" : : "r" (r)) + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +fenv_t __fe_dfl_env = 0; + +/* + * The feclearexcept() function clears the supported floating-point exceptions + * represented by `excepts'. + */ +int +feclearexcept(int excepts) +{ + fexcept_t r; + + __mrs_fpsr(r); + r &= ~excepts; + __msr_fpsr(r); + return (0); +} +DEF_STD(feclearexcept); + +/* + * The fegetexceptflag() function stores an implementation-defined + * representation of the states of the floating-point status flags indicated by + * the argument excepts in the object pointed to by the argument flagp. + */ +int +fegetexceptflag(fexcept_t *flagp, int excepts) +{ + fexcept_t r; + + __mrs_fpsr(r); + *flagp = r & excepts; + return (0); +} +DEF_STD(fegetexceptflag); + +/* + * The feraiseexcept() function raises the supported floating-point exceptions + * represented by the argument `excepts'. + */ +int +feraiseexcept(int excepts) +{ + fexcept_t r; + + __mrs_fpsr(r); + r |= excepts; + __msr_fpsr(r); + return (0); +} +DEF_STD(feraiseexcept); + +/* + * This function sets the floating-point status flags indicated by the argument + * `excepts' to the states stored in the object pointed to by `flagp'. It does + * NOT raise any floating-point exceptions, but only sets the