xref: /openbsd-src/lib/libc/arch/riscv64/gen/flt_rounds.c (revision 0bcd3eeb4adbf1b8039f4f7f536d66f59ccf461f)
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 
11 static 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 
22 int
__flt_rounds(void)23 __flt_rounds(void)
24 {
25 	uint32_t frm;
26 
27 	__asm volatile ("frrm %0" : "=r"(frm));
28 	return map[frm];
29 }
30 DEF_STRONG(__flt_rounds);
31