diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2018-02-28 11:16:55 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2018-02-28 11:16:55 +0000 |
commit | 732e41a316051fbfd8c259533be6250e0748fac7 (patch) | |
tree | 0ab758bf19004058fdf298dfeb376b42555eacb1 /lib/libc/arch | |
parent | e2c0e1db5f2744114d240b5c3ce5763ad64798d5 (diff) |
Change floating-point mode/environment control functions to operate on
both the hardfloat (FPU registers) and softfloat (software) state. This
makes these functions work correctly when mixing hardfloat and softfloat
code. Disable trapping for softfloat since most (if not all) ARMv7 and
ARMv8 hardware that is on the market doesn't support trapping of
floating-point exceptions.
ok patrick@
Diffstat (limited to 'lib/libc/arch')
-rw-r--r-- | lib/libc/arch/arm/Makefile.inc | 5 | ||||
-rw-r--r-- | lib/libc/arch/arm/gen/fpgetmask.c | 26 | ||||
-rw-r--r-- | lib/libc/arch/arm/gen/fpgetround.c | 37 | ||||
-rw-r--r-- | lib/libc/arch/arm/gen/fpgetsticky.c | 38 | ||||
-rw-r--r-- | lib/libc/arch/arm/gen/fpsetmask.c | 26 | ||||
-rw-r--r-- | lib/libc/arch/arm/gen/fpsetround.c | 41 | ||||
-rw-r--r-- | lib/libc/arch/arm/gen/fpsetsticky.c | 43 |
7 files changed, 215 insertions, 1 deletions
diff --git a/lib/libc/arch/arm/Makefile.inc b/lib/libc/arch/arm/Makefile.inc index a20ce0c317e..6ca8e6e4f51 100644 --- a/lib/libc/arch/arm/Makefile.inc +++ b/lib/libc/arch/arm/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.7 2016/09/17 20:13:48 kettenis Exp $ +# $OpenBSD: Makefile.inc,v 1.8 2018/02/28 11:16:54 kettenis Exp $ # $NetBSD: Makefile.inc,v 1.5 2002/07/10 04:29:06 thorpej Exp $ .include <bsd.own.mk> @@ -7,6 +7,9 @@ CERROR= cerror.S CPPFLAGS += -DSOFTFLOAT +# Override softfloat implementations of FP mode control functions +.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen + SOFTFLOAT_BITS=32 .include <arch/arm/softfloat/Makefile.inc> diff --git a/lib/libc/arch/arm/gen/fpgetmask.c b/lib/libc/arch/arm/gen/fpgetmask.c new file mode 100644 index 00000000000..7b8ee7c5073 --- /dev/null +++ b/lib/libc/arch/arm/gen/fpgetmask.c @@ -0,0 +1,26 @@ +/* $OpenBSD: fpgetmask.c,v 1.1 2018/02/28 11:16:54 kettenis Exp $ */ +/* + * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ieeefp.h> + +__weak_alias(_fpgetmask,fpgetmask); + +fp_except +fpgetmask(void) +{ + return 0; +} diff --git a/lib/libc/arch/arm/gen/fpgetround.c b/lib/libc/arch/arm/gen/fpgetround.c new file mode 100644 index 00000000000..aac7e1ce055 --- /dev/null +++ b/lib/libc/arch/arm/gen/fpgetround.c @@ -0,0 +1,37 @@ +/* $OpenBSD: fpgetround.c,v 1.1 2018/02/28 11:16:54 kettenis Exp $ */ +/* + * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ieeefp.h> +#ifdef SOFTFLOAT_FOR_GCC +#include "softfloat-for-gcc.h" +#endif +#include "milieu.h" +#include <softfloat.h> +#include <stdint.h> + +__weak_alias(_fpgetround,fpgetround); + +fp_rnd +fpgetround(void) +{ + uint32_t fpscr; + + __asm volatile("vmrs %0, fpscr" : "=r" (fpscr)); + + return ((fpscr >> 22) & 3); +} +DEF_WEAK(fpgetround); diff --git a/lib/libc/arch/arm/gen/fpgetsticky.c b/lib/libc/arch/arm/gen/fpgetsticky.c new file mode 100644 index 00000000000..66ca420431d --- /dev/null +++ b/lib/libc/arch/arm/gen/fpgetsticky.c @@ -0,0 +1,38 @@ +/* $OpenBSD: fpgetsticky.c,v 1.1 2018/02/28 11:16:54 kettenis Exp $ */ +/* + * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ieeefp.h> +#ifdef SOFTFLOAT_FOR_GCC +#include "softfloat-for-gcc.h" +#endif +#include "milieu.h" +#include <softfloat.h> + +#define FP_X_MASK (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) + +__weak_alias(_fpgetsticky,fpgetsticky); + +fp_except +fpgetsticky(void) +{ + fp_except old; + + __asm volatile("vmrs %0, fpscr" : "=r" (old)); + old |= float_exception_flags; + + return (old & FP_X_MASK); +} diff --git a/lib/libc/arch/arm/gen/fpsetmask.c b/lib/libc/arch/arm/gen/fpsetmask.c new file mode 100644 index 00000000000..09feb48ee05 --- /dev/null +++ b/lib/libc/arch/arm/gen/fpsetmask.c @@ -0,0 +1,26 @@ +/* $OpenBSD: fpsetmask.c,v 1.1 2018/02/28 11:16:54 kettenis Exp $ */ +/* + * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ieeefp.h> + +__weak_alias(_fpsetmask,fpsetmask); + +fp_except +fpsetmask(fp_except mask) +{ + return 0; +} diff --git a/lib/libc/arch/arm/gen/fpsetround.c b/lib/libc/arch/arm/gen/fpsetround.c new file mode 100644 index 00000000000..7e46f4f8fb9 --- /dev/null +++ b/lib/libc/arch/arm/gen/fpsetround.c @@ -0,0 +1,41 @@ +/* $OpenBSD: fpsetround.c,v 1.1 2018/02/28 11:16:54 kettenis Exp $ */ +/* + * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ieeefp.h> +#ifdef SOFTFLOAT_FOR_GCC +#include "softfloat-for-gcc.h" +#endif +#include "milieu.h" +#include <softfloat.h> +#include <stdint.h> + +__weak_alias(_fpsetround,fpsetround); + +fp_rnd +fpsetround(fp_rnd rnd_dir) +{ + uint32_t old, new; + + __asm volatile("vmrs %0, fpscr" : "=r" (old)); + new = old & ~(3 << 22); + new |= (rnd_dir & 3) << 22; + __asm volatile("vmsr fpscr, %0" :: "r" (new)); + + float_rounding_mode = rnd_dir; + + return ((old >> 22) & 3); +} diff --git a/lib/libc/arch/arm/gen/fpsetsticky.c b/lib/libc/arch/arm/gen/fpsetsticky.c new file mode 100644 index 00000000000..839151edb0a --- /dev/null +++ b/lib/libc/arch/arm/gen/fpsetsticky.c @@ -0,0 +1,43 @@ +/* $OpenBSD: fpsetsticky.c,v 1.1 2018/02/28 11:16:54 kettenis Exp $ */ +/* + * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ieeefp.h> +#ifdef SOFTFLOAT_FOR_GCC +#include "softfloat-for-gcc.h" +#endif +#include "milieu.h" +#include <softfloat.h> + +#define FP_X_MASK (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) + +__weak_alias(_fpsetsticky,fpsetsticky); + +fp_except +fpsetsticky(fp_except except) +{ + fp_except old, new; + + __asm volatile("vmrs %0, fpscr" : "=r" (old)); + new = old & ~(FP_X_MASK); + new |= (except & FP_X_MASK); + __asm volatile("vmsr fpscr, %0" :: "r" (new)); + + old |= float_exception_flags; + float_exception_flags = except; + + return (old & FP_X_MASK); +} |