1/*	$OpenBSD: flt_rounds.c,v 1.1 2021/04/28 15:38:59 kettenis Exp $	*/
2
3/*
4 * Written by Mark Kettenis based on the hppa version written by
5 * Miodrag Vallat.  Public domain.
6 */
7
8#include <sys/types.h>
9#include <float.h>
10
11static const int map[] = {
12	1,	/* round to nearest, ties to even */
13	0,	/* round to zero */
14	3,	/* round to negative infinity */
15	2,	/* round to positive infinity */
16	4,	/* round to nearest, ties away from zero */
17	-1,	/* invalid */
18	-1,	/* invalid */
19	-1	/* invalid */
20};
21
22int
23__flt_rounds(void)
24{
25	uint32_t frm;
26
27	__asm volatile ("frrm %0" : "=r"(frm));
28	return map[frm];
29}
30DEF_STRONG(__flt_rounds);
31