2.9
[glibc/nacl-glibc.git] / sysdeps / mach / alpha / setfpucw.c
bloba2887c8dfbf2adb7809616eed95a15663b0e7e3d
1 /* Set FP exception mask and rounding mode. Mach/Alpha version.
2 Copyright (C) 2002 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>
23 #define FPCR_DYN_SHIFT 58 /* first dynamic rounding mode bit */
24 #define FPCR_DYN_CHOPPED (0x0UL << FPCR_DYN_SHIFT) /* towards 0 */
25 #define FPCR_DYN_MINUS (0x1UL << FPCR_DYN_SHIFT) /* towards -INF */
26 #define FPCR_DYN_NORMAL (0x2UL << FPCR_DYN_SHIFT) /* towards nearest */
27 #define FPCR_DYN_PLUS (0x3UL << FPCR_DYN_SHIFT) /* towards +INF */
28 #define FPCR_DYN_MASK (0x3UL << FPCR_DYN_SHIFT)
30 static inline unsigned long
31 rdfpcr (void)
33 unsigned long fpcr;
34 asm ("excb; mf_fpcr %0" : "=f"(fpcr));
35 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;
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 /* XXX trap bits? */
68 __fpu_control = fpu_control; /* update global copy */