1998-03-01 18:52 H.J. Lu (hjl@gnu.org) * sysdeps/unix/sysv/linux/alpha...
[glibc.git] / sysdeps / unix / sysv / linux / alpha / setfpucw.c
blob9133c81110ee58047ef9721fb625ccd86173ea87
1 /* Set FP exception mask and rounding mode.
2 Copyright (C) 1996, 1997 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <fpu_control.h>
21 #include <asm/fpu.h>
24 extern void __ieee_set_fp_control (unsigned long);
25 extern unsigned long __ieee_get_fp_control (void);
27 static inline unsigned long
28 rdfpcr (void)
30 unsigned long fpcr;
31 asm ("excb; mf_fpcr %0" : "=f"(fpcr));
32 return fpcr;
36 static inline void
37 wrfpcr (unsigned long fpcr)
39 asm volatile ("mt_fpcr %0; excb" : : "f"(fpcr));
43 void
44 __setfpucw (unsigned short fpu_control)
46 unsigned long fpcr = 0, fpcw = 0;
48 if (!fpu_control)
49 fpu_control = _FPU_DEFAULT;
51 /* first, set dynamic rounding mode: */
53 fpcr = rdfpcr();
54 fpcr &= ~FPCR_DYN_MASK;
55 switch (fpu_control & 0xc00)
57 case _FPU_RC_NEAREST: fpcr |= FPCR_DYN_NORMAL; break;
58 case _FPU_RC_DOWN: fpcr |= FPCR_DYN_MINUS; break;
59 case _FPU_RC_UP: fpcr |= FPCR_DYN_PLUS; break;
60 case _FPU_RC_ZERO: fpcr |= FPCR_DYN_CHOPPED; break;
62 wrfpcr(fpcr);
64 /* now tell kernel about traps that we like to hear about: */
66 fpcw = __ieee_get_fp_control();
67 fpcw &= ~IEEE_TRAP_ENABLE_MASK;
69 if (!(fpu_control & _FPU_MASK_IM)) fpcw |= IEEE_TRAP_ENABLE_INV;
70 if (!(fpu_control & _FPU_MASK_DM)) fpcw |= IEEE_TRAP_ENABLE_UNF;
71 if (!(fpu_control & _FPU_MASK_ZM)) fpcw |= IEEE_TRAP_ENABLE_DZE;
72 if (!(fpu_control & _FPU_MASK_OM)) fpcw |= IEEE_TRAP_ENABLE_OVF;
73 if (!(fpu_control & _FPU_MASK_PM)) fpcw |= IEEE_TRAP_ENABLE_INE;
75 __fpu_control = fpu_control; /* update global copy */
77 __ieee_set_fp_control(fpcw);