xref: /openbsd/sys/arch/alpha/include/ieeefp.h (revision 09467b48)
1 /*	$OpenBSD: ieeefp.h,v 1.6 2011/03/23 16:54:34 pirofti Exp $	*/
2 /*	$NetBSD: ieeefp.h,v 1.1 1995/04/29 01:09:17 cgd Exp $	*/
3 
4 /*
5  * Written by J.T. Conklin, Apr 28, 1995
6  * Public domain.
7  */
8 
9 #ifndef _MACHINE_IEEEFP_H_
10 #define _MACHINE_IEEEFP_H_
11 
12 typedef int fp_except;
13 
14 #ifdef _KERNEL
15 
16 #include <sys/param.h>
17 #include <sys/proc.h>
18 #include <machine/fpu.h>
19 #include <machine/cpu.h>
20 
21 /* FP_X_IOV is intentionally omitted from the architecture flags mask */
22 
23 #define	FP_AA_FLAGS (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP)
24 
25 #define float_raise(f)						\
26 	do curproc->p_md.md_flags |= OPENBSD_FLAG_TO_FP_C(f);	\
27 	while(0)
28 
29 #define	float_set_inexact()	float_raise(FP_X_IMP)
30 #define	float_set_invalid()	float_raise(FP_X_INV)
31 #define	fpgetround()		(alpha_read_fpcr() >> 58 & 3)
32 
33 #endif
34 
35 #define	FP_X_INV	0x01	/* invalid operation exception */
36 #define	FP_X_DZ		0x02	/* divide-by-zero exception */
37 #define	FP_X_OFL	0x04	/* overflow exception */
38 #define	FP_X_UFL	0x08	/* underflow exception */
39 #define	FP_X_IMP	0x10	/* imprecise (loss of precision; "inexact") */
40 #define	FP_X_IOV	0x20    /* integer overflow */
41 
42 /*
43  * fp_rnd bits match the fpcr, below, as well as bits 12:11
44  * in fp operate instructions
45  */
46 typedef enum {
47     FP_RZ = 0,			/* round to zero (truncate) */
48     FP_RM = 1,			/* round toward negative infinity */
49     FP_RN = 2,			/* round to nearest representable number */
50     FP_RP = 3			/* round toward positive infinity */
51 } fp_rnd;
52 
53 #endif /* _MACHINE_IEEEFP_H_ */
54