1 /* Set FP exception mask and rounding mode.
2 Copyright (C) 1996, 1997, 1998, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <fpu_control.h>
22 extern void __ieee_set_fp_control (unsigned long);
23 libc_hidden_proto(__ieee_set_fp_control
)
25 extern unsigned long __ieee_get_fp_control (void);
26 libc_hidden_proto(__ieee_get_fp_control
)
28 static inline unsigned long
32 asm ("excb; mf_fpcr %0" : "=f"(fpcr
));
38 wrfpcr (unsigned long fpcr
)
40 asm volatile ("mt_fpcr %0; excb" : : "f"(fpcr
));
45 __setfpucw (fpu_control_t fpu_control
)
47 unsigned long fpcr
= 0, fpcw
= 0;
50 fpu_control
= _FPU_DEFAULT
;
52 /* first, set dynamic rounding mode: */
55 fpcr
&= ~FPCR_DYN_MASK
;
56 switch (fpu_control
& 0xc00)
58 case _FPU_RC_NEAREST
: fpcr
|= FPCR_DYN_NORMAL
; break;
59 case _FPU_RC_DOWN
: fpcr
|= FPCR_DYN_MINUS
; break;
60 case _FPU_RC_UP
: fpcr
|= FPCR_DYN_PLUS
; break;
61 case _FPU_RC_ZERO
: fpcr
|= FPCR_DYN_CHOPPED
; break;
65 /* now tell kernel about traps that we like to hear about: */
67 fpcw
= __ieee_get_fp_control();
68 fpcw
&= ~IEEE_TRAP_ENABLE_MASK
;
70 if (!(fpu_control
& _FPU_MASK_IM
)) fpcw
|= IEEE_TRAP_ENABLE_INV
;
71 if (!(fpu_control
& _FPU_MASK_DM
)) fpcw
|= IEEE_TRAP_ENABLE_UNF
;
72 if (!(fpu_control
& _FPU_MASK_ZM
)) fpcw
|= IEEE_TRAP_ENABLE_DZE
;
73 if (!(fpu_control
& _FPU_MASK_OM
)) fpcw
|= IEEE_TRAP_ENABLE_OVF
;
74 if (!(fpu_control
& _FPU_MASK_PM
)) fpcw
|= IEEE_TRAP_ENABLE_INE
;
76 __fpu_control
= fpu_control
; /* update global copy */
78 __ieee_set_fp_control(fpcw
);