-/* $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>
*
#include <ieeefp.h>
-__weak_alias(_fpgetmask,fpgetmask);
-
fp_except
fpgetmask(void)
{
return 0;
}
+DEF_WEAK(fpgetmask);
--- /dev/null
+/* $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);
--- /dev/null
+/* $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);
-/* $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>
*
#include <ieeefp.h>
-__weak_alias(_fpsetmask,fpsetmask);
-
fp_except
fpsetmask(fp_except mask)
{
return 0;
}
+DEF_WEAK(fpsetmask);
--- /dev/null
+/* $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);
--- /dev/null
+/* $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);
-/* $OpenBSD: ieeefp.h,v 1.1 2021/04/23 02:42:16 drahn Exp $ */
-/* $NetBSD: ieeefp.h,v 1.1 2001/01/10 19:02:06 bjh21 Exp $ */
+/* $OpenBSD: ieeefp.h,v 1.2 2021/04/29 17:19:18 kettenis Exp $ */
/*
* Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995
#ifndef _MACHINE_IEEEFP_H_
#define _MACHINE_IEEEFP_H_
-/* FP exception codes */
-
-#define FP_EXCEPT_INV 0
-#define FP_EXCEPT_DZ 1
-#define FP_EXCEPT_OFL 2
-#define FP_EXCEPT_UFL 3
-#define FP_EXCEPT_IMP 4
-
-/* Exception type (used by fpsetmask() et al.) */
-
typedef int fp_except;
-
-/* Bit defines for fp_except */
-
-#define FP_X_INV (1 << FP_EXCEPT_INV) /* invalid operation exception */
-#define FP_X_DZ (1 << FP_EXCEPT_DZ) /* divide-by-zero exception */
-#define FP_X_OFL (1 << FP_EXCEPT_OFL) /* overflow exception */
-#define FP_X_UFL (1 << FP_EXCEPT_UFL) /* underflow exception */
-#define FP_X_IMP (1 << FP_EXCEPT_IMP) /* imprecise (loss of precision; "inexact") */
-#define FP_X_MASK 0x1f
-
-/* Rounding modes */
+#define FP_X_INV 0x10 /* invalid operation exception */
+#define FP_X_DZ 0x08 /* divide-by-zero exception */
+#define FP_X_OFL 0x04 /* overflow exception */
+#define FP_X_UFL 0x02 /* underflow exception */
+#define FP_X_IMP 0x01 /* imprecise (loss of precision) */
typedef enum {
FP_RN=0, /* round to nearest representable number */
- FP_RP=1, /* round toward positive infinity */
+ FP_RZ=1 /* round to zero (truncate) */
FP_RM=2, /* round toward negative infinity */
- FP_RZ=3 /* round to zero (truncate) */
+ FP_RP=3, /* round toward positive infinity */
} fp_rnd;
#endif /* _MACHINE_IEEEFP_H_ */