diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2021-04-29 17:19:19 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2021-04-29 17:19:19 +0000 |
commit | f3fed61be561efabda79c6cefec7d71e24624162 (patch) | |
tree | 856b7aa6c6bc0b36be434e4172d18c84858135f0 /lib/libc | |
parent | c915d3265d1bd85a1d344f690c98e75550a13ffc (diff) |
Clean up <machine/ieeefp.h> and make sure the rounding mode bits match the
hardware. Implement fp[gs]etround(3) and fp[gs]etsticky(3) and tweak
the fp[gs]etmask(3) implementation to provide the right weak symbols.
This implementation deliberately ignores the additional
"round to nearest, away from zero" as this interface is derived from
i386-specific code and the i387 FPU doesn't implement such a rounding
mode. This is a legacy API and code should use <fenv.h> instead.
ok drahn@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/arch/riscv64/gen/fpgetmask.c | 5 | ||||
-rw-r--r-- | lib/libc/arch/riscv64/gen/fpgetround.c | 29 | ||||
-rw-r--r-- | lib/libc/arch/riscv64/gen/fpgetsticky.c | 29 | ||||
-rw-r--r-- | lib/libc/arch/riscv64/gen/fpsetmask.c | 5 | ||||
-rw-r--r-- | lib/libc/arch/riscv64/gen/fpsetround.c | 31 | ||||
-rw-r--r-- | lib/libc/arch/riscv64/gen/fpsetsticky.c | 29 |
6 files changed, 122 insertions, 6 deletions
diff --git a/lib/libc/arch/riscv64/gen/fpgetmask.c b/lib/libc/arch/riscv64/gen/fpgetmask.c index 6e94f99bd33..4d8fac984e2 100644 --- a/lib/libc/arch/riscv64/gen/fpgetmask.c +++ b/lib/libc/arch/riscv64/gen/fpgetmask.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpgetmask.c,v 1.1 2021/04/28 08:22:56 kettenis Exp $ */ +/* $OpenBSD: fpgetmask.c,v 1.2 2021/04/29 17:19:18 kettenis Exp $ */ /* * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> * @@ -17,10 +17,9 @@ #include <ieeefp.h> -__weak_alias(_fpgetmask,fpgetmask); - fp_except fpgetmask(void) { return 0; } +DEF_WEAK(fpgetmask); diff --git a/lib/libc/arch/riscv64/gen/fpgetround.c b/lib/libc/arch/riscv64/gen/fpgetround.c new file mode 100644 index 00000000000..6d2351f9d1e --- /dev/null +++ b/lib/libc/arch/riscv64/gen/fpgetround.c @@ -0,0 +1,29 @@ +/* $OpenBSD: fpgetround.c,v 1.1 2021/04/29 17:19:18 kettenis Exp $ */ +/* + * Copyright (c) 2021 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 <sys/types.h> +#include <ieeefp.h> + +fp_rnd +fpgetround(void) +{ + uint32_t frm; + + __asm volatile ("frrm %0" : "=r"(frm)); + return frm & 0x3; +} +DEF_WEAK(fpgetround); diff --git a/lib/libc/arch/riscv64/gen/fpgetsticky.c b/lib/libc/arch/riscv64/gen/fpgetsticky.c new file mode 100644 index 00000000000..81a14b0dcda --- /dev/null +++ b/lib/libc/arch/riscv64/gen/fpgetsticky.c @@ -0,0 +1,29 @@ +/* $OpenBSD: fpgetsticky.c,v 1.1 2021/04/29 17:19:18 kettenis Exp $ */ +/* + * Copyright (c) 2021 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 <sys/types.h> +#include <ieeefp.h> + +fp_except +fpgetsticky(void) +{ + uint32_t fflags; + + __asm volatile ("frflags %0" : "=r"(fflags)); + return fflags; +} +DEF_WEAK(fpgetsticky); diff --git a/lib/libc/arch/riscv64/gen/fpsetmask.c b/lib/libc/arch/riscv64/gen/fpsetmask.c index 03485db6c93..d4b1edd5d79 100644 --- a/lib/libc/arch/riscv64/gen/fpsetmask.c +++ b/lib/libc/arch/riscv64/gen/fpsetmask.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fpsetmask.c,v 1.1 2021/04/28 08:22:56 kettenis Exp $ */ +/* $OpenBSD: fpsetmask.c,v 1.2 2021/04/29 17:19:18 kettenis Exp $ */ /* * Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org> * @@ -17,10 +17,9 @@ #include <ieeefp.h> -__weak_alias(_fpsetmask,fpsetmask); - fp_except fpsetmask(fp_except mask) { return 0; } +DEF_WEAK(fpsetmask); diff --git a/lib/libc/arch/riscv64/gen/fpsetround.c b/lib/libc/arch/riscv64/gen/fpsetround.c new file mode 100644 index 00000000000..e9e26b32466 --- /dev/null +++ b/lib/libc/arch/riscv64/gen/fpsetround.c @@ -0,0 +1,31 @@ +/* $OpenBSD: fpsetround.c,v 1.1 2021/04/29 17:19:18 kettenis Exp $ */ +/* + * Copyright (c) 2021 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 <sys/types.h> +#include <ieeefp.h> + +fp_rnd +fpsetround(fp_rnd rnd_dir) +{ + uint32_t frm; + + __asm volatile ("fsrm %0, %1" : "=r"(frm) : "r"(rnd_dir)); + + /* Truncating to 2 bits means both RNE and RMM become FP_RN. */ + return frm & 0x3; +} +DEF_WEAK(fpsetround); diff --git a/lib/libc/arch/riscv64/gen/fpsetsticky.c b/lib/libc/arch/riscv64/gen/fpsetsticky.c new file mode 100644 index 00000000000..a7069c38b75 --- /dev/null +++ b/lib/libc/arch/riscv64/gen/fpsetsticky.c @@ -0,0 +1,29 @@ +/* $OpenBSD: fpsetsticky.c,v 1.1 2021/04/29 17:19:18 kettenis Exp $ */ +/* + * Copyright (c) 2021 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 <sys/types.h> +#include <ieeefp.h> + +fp_except +fpsetsticky(fp_except sticky) +{ + uint32_t fflags; + + __asm volatile ("fsflags %0, %1" : "=r"(fflags) : "r"(sticky)); + return fflags; +} +DEF_WEAK(fpsetsticky); |