Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / ieee-utils / fp-gnux86.c
1 /* ieee-utils/fp-gnux86.c
2  * 
3  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or (at
8  * your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include <stdio.h>
21 #include <fpu_control.h>
22 #include <gsl/gsl_errno.h>
23 #include <gsl/gsl_ieee_utils.h>
24
25   /* Handle libc5, where _FPU_SETCW is not available, suggested by
26      OKUJI Yoshinori <okuji@gnu.org> and Evgeny Stambulchik
27      <fnevgeny@plasma-gate.weizmann.ac.il> */
28
29 #ifndef _FPU_SETCW
30 #include <i386/fpu_control.h>
31 #define _FPU_SETCW(cw) __setfpucw(cw)
32 #endif
33
34 int
35 gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
36 {
37   unsigned short mode = 0 ;
38
39   switch (precision)
40     {
41     case GSL_IEEE_SINGLE_PRECISION:
42       mode |= _FPU_SINGLE ;
43       break ;
44     case GSL_IEEE_DOUBLE_PRECISION:
45       mode |= _FPU_DOUBLE ;
46       break ;
47     case GSL_IEEE_EXTENDED_PRECISION:
48       mode |= _FPU_EXTENDED ;
49       break ;
50     default:
51       mode |= _FPU_EXTENDED ;
52     }
53
54   switch (rounding)
55     {
56     case GSL_IEEE_ROUND_TO_NEAREST:
57       mode |= _FPU_RC_NEAREST ;
58       break ;
59     case GSL_IEEE_ROUND_DOWN:
60       mode |= _FPU_RC_DOWN ;
61       break ;
62     case GSL_IEEE_ROUND_UP:
63       mode |= _FPU_RC_UP ;
64       break ;
65     case GSL_IEEE_ROUND_TO_ZERO:
66       mode |= _FPU_RC_ZERO ;
67       break ;
68     default:
69       mode |= _FPU_RC_NEAREST ;
70     }
71
72   if (exception_mask & GSL_IEEE_MASK_INVALID)
73     mode |= _FPU_MASK_IM ;
74
75   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
76     mode |= _FPU_MASK_DM ;
77
78   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
79     mode |= _FPU_MASK_ZM ;
80
81   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
82     mode |= _FPU_MASK_OM ;
83
84   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
85     mode |= _FPU_MASK_UM ;
86
87   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
88     {
89       mode &= ~ _FPU_MASK_PM ;
90     }
91   else
92     {
93       mode |= _FPU_MASK_PM ;
94     }
95
96   _FPU_SETCW(mode) ;
97
98 #if HAVE_FPU_X86_SSE
99 #define _FPU_SETMXCSR(cw_sse) asm volatile ("ldmxcsr %0" : : "m" (*&cw_sse))
100   {
101     unsigned int mode_sse = 0;
102
103     mode_sse |= (mode & 0x3f)<<7;  /* exception masks */
104     mode_sse |= (mode & 0xc00)<<3;    /* rounding control */
105     
106     _FPU_SETMXCSR(mode_sse);
107   }
108 #endif
109
110   return GSL_SUCCESS ;
111 }