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