xref: /dflybsd-src/contrib/gcc-4.7/libgcc/config/i386/crtprec.c (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /*
2*e4b17023SJohn Marino  * Copyright (C) 2007, 2009 Free Software Foundation, Inc.
3*e4b17023SJohn Marino  *
4*e4b17023SJohn Marino  * This file is free software; you can redistribute it and/or modify it
5*e4b17023SJohn Marino  * under the terms of the GNU General Public License as published by the
6*e4b17023SJohn Marino  * Free Software Foundation; either version 3, or (at your option) any
7*e4b17023SJohn Marino  * later version.
8*e4b17023SJohn Marino  *
9*e4b17023SJohn Marino  * This file is distributed in the hope that it will be useful, but
10*e4b17023SJohn Marino  * WITHOUT ANY WARRANTY; without even the implied warranty of
11*e4b17023SJohn Marino  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12*e4b17023SJohn Marino  * General Public License for more details.
13*e4b17023SJohn Marino  *
14*e4b17023SJohn Marino  * Under Section 7 of GPL version 3, you are granted additional
15*e4b17023SJohn Marino  * permissions described in the GCC Runtime Library Exception, version
16*e4b17023SJohn Marino  * 3.1, as published by the Free Software Foundation.
17*e4b17023SJohn Marino  *
18*e4b17023SJohn Marino  * You should have received a copy of the GNU General Public License and
19*e4b17023SJohn Marino  * a copy of the GCC Runtime Library Exception along with this program;
20*e4b17023SJohn Marino  * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21*e4b17023SJohn Marino  * <http://www.gnu.org/licenses/>.
22*e4b17023SJohn Marino  */
23*e4b17023SJohn Marino 
24*e4b17023SJohn Marino #if __PREC == 32
25*e4b17023SJohn Marino  #define X87CW		(0 << 8)	/* Single precision (24 bits) */
26*e4b17023SJohn Marino #elif __PREC == 64
27*e4b17023SJohn Marino  #define X87CW		(2 << 8)	/* Double precision (53 bits) */
28*e4b17023SJohn Marino #elif __PREC == 80
29*e4b17023SJohn Marino  #define X87CW		(3 << 8)	/* Extended precision (64 bits) */
30*e4b17023SJohn Marino #else
31*e4b17023SJohn Marino  #error "Wrong precision requested."
32*e4b17023SJohn Marino #endif
33*e4b17023SJohn Marino 
34*e4b17023SJohn Marino #define X87CW_PCMASK	(3 << 8)
35*e4b17023SJohn Marino 
36*e4b17023SJohn Marino static void __attribute__((constructor))
set_precision(void)37*e4b17023SJohn Marino set_precision (void)
38*e4b17023SJohn Marino {
39*e4b17023SJohn Marino   unsigned short int cwd;
40*e4b17023SJohn Marino 
41*e4b17023SJohn Marino   asm volatile ("fstcw\t%0" : "=m" (cwd));
42*e4b17023SJohn Marino 
43*e4b17023SJohn Marino   cwd &= ~X87CW_PCMASK;
44*e4b17023SJohn Marino   cwd |= X87CW;
45*e4b17023SJohn Marino 
46*e4b17023SJohn Marino   asm volatile ("fldcw\t%0" : : "m" (cwd));
47*e4b17023SJohn Marino }
48