2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / alpha / setfpucw.c
bloba7e3a558120ab7c6e7078622924030bf8dd5710e
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <fpu_control.h>
21 #include <asm/fpu.h>
23 extern void __ieee_set_fp_control (unsigned long);
24 libc_hidden_proto(__ieee_set_fp_control)
26 extern unsigned long __ieee_get_fp_control (void);
27 libc_hidden_proto(__ieee_get_fp_control)
29 static inline unsigned long
30 rdfpcr (void)
32 unsigned long fpcr;
33 asm ("excb; mf_fpcr %0" : "=f"(fpcr));
34 return fpcr;
38 static inline void
39 wrfpcr (unsigned long fpcr)
41 asm volatile ("mt_fpcr %0; excb" : : "f"(fpcr));
45 void
46 __setfpucw (fpu_control_t fpu_control)
48 unsigned long fpcr = 0, fpcw = 0;
50 if (!fpu_control)
51 fpu_control = _FPU_DEFAULT;
53 /* first, set dynamic rounding mode: */
55 fpcr = rdfpcr();
56 fpcr &= ~FPCR_DYN_MASK;
57 switch (fpu_control & 0xc00)
59 case _FPU_RC_NEAREST: fpcr |= FPCR_DYN_NORMAL; break;
60 case _FPU_RC_DOWN: fpcr |= FPCR_DYN_MINUS; break;
61 case _FPU_RC_UP: fpcr |= FPCR_DYN_PLUS; break;
62 case _FPU_RC_ZERO: fpcr |= FPCR_DYN_CHOPPED; break;
64 wrfpcr(fpcr);
66 /* now tell kernel about traps that we like to hear about: */
68 fpcw = __ieee_get_fp_control();
69 fpcw &= ~IEEE_TRAP_ENABLE_MASK;
71 if (!(fpu_control & _FPU_MASK_IM)) fpcw |= IEEE_TRAP_ENABLE_INV;
72 if (!(fpu_control & _FPU_MASK_DM)) fpcw |= IEEE_TRAP_ENABLE_UNF;
73 if (!(fpu_control & _FPU_MASK_ZM)) fpcw |= IEEE_TRAP_ENABLE_DZE;
74 if (!(fpu_control & _FPU_MASK_OM)) fpcw |= IEEE_TRAP_ENABLE_OVF;
75 if (!(fpu_control & _FPU_MASK_PM)) fpcw |= IEEE_TRAP_ENABLE_INE;
77 __fpu_control = fpu_control; /* update global copy */
79 __ieee_set_fp_control(fpcw);