riscv: Make feraiseexcept actually raise the given exceptions.

Doing

	fexcept_t ex = 0;
	fesetexceptflag(&ex, excepts);

has the effect of _clearing_ all the exceptions in excepts.  Using
fesetexceptflag doesn't make this easier, because we would have to
record which exceptions were already raised.  So just set the fflags
bits in the fcsr register directly.
This commit is contained in:
riastradh 2024-05-17 02:11:07 +00:00
parent af39a49700
commit 70dffce551
1 changed files with 3 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fenv.c,v 1.4 2023/05/07 12:41:47 skrll Exp $ */
/* $NetBSD: fenv.c,v 1.5 2024/05/17 02:11:07 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: fenv.c,v 1.4 2023/05/07 12:41:47 skrll Exp $");
__RCSID("$NetBSD: fenv.c,v 1.5 2024/05/17 02:11:07 riastradh Exp $");
#include "namespace.h"
@ -114,19 +114,15 @@ fegetexceptflag(fexcept_t *flagp, int excepts)
* The standard explicitly allows us to execute an instruction that has the
* exception as a side effect, but we choose to manipulate the status register
* directly.
*
* The validation of input is being deferred to fesetexceptflag().
*/
int
feraiseexcept(int excepts)
{
fexcept_t ex = 0;
_DIAGASSERT((excepts & ~FE_ALL_EXCEPT) == 0);
excepts &= FE_ALL_EXCEPT;
fesetexceptflag(&ex, excepts);
/* XXX exception magic XXX */
fcsr_fflags_write(fcsr_fflags_read() | excepts);
/* Success */
return 0;