## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# csutil/fpu80x86.h

    00001 /*
    00002     Copyright (C) 1998 by Jorrit Tyberghein
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public
    00015     License along with this library; if not, write to the Free
    00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_FPU80X86_H__
    00020 #define __CS_FPU80X86_H__
    00021
    00022 #if defined(CS_PROCESSOR_X86) && defined(CS_COMPILER_GCC)
    00023
    00024 /*
    00025      ---- ---- --XX XXXX = MCW_EM - exception masks (1=handle exception internally, 0=fault)
    00026      ---- ---- ---- ---X = EM_INVALID - invalid operation
    00027      ---- ---- ---- --X- = EM_DENORMAL - denormal operand
    00028      ---- ---- ---- -X-- = EM_ZERODIVIDE - divide by zero
    00029      ---- ---- ---- X--- = EM_OVERFLOW - overflow
    00030      ---- ---- ---X ---- = EM_UNDERFLOW - underflow
    00031      ---- ---- --X- ---- = EM_INEXACT - rounding was required
    00032      ---- --XX ---- ---- = MCW_PC - precision control
    00033      ---- --00 ---- ---- = PC_24 - single precision
    00034      ---- --10 ---- ---- = PC_53 - double precision
    00035      ---- --11 ---- ---- = PC_64 - extended precision
    00036      ---- XX-- ---- ---- = MCW_RC - rounding control
    00037      ---- 00-- ---- ---- = RC_NEAR - round to nearest
    00038      ---- 01-- ---- ---- = RC_DOWN - round towards -Inf
    00039      ---- 10-- ---- ---- = RC_UP - round towards +Inf
    00040      ---- 11-- ---- ---- = RC_CHOP - round towards zero
    00041      ---X ---- ---- ---- = MCW_IC - infinity control (obsolete, always affine)
    00042      ---0 ---- ---- ---- = IC_AFFINE - -Inf < +Inf
    00043      ---1 ---- ---- ---- = IC_PROJECTIVE - -Inf == +Inf
    00044 */
    00045
    00046 static inline unsigned int csControl87(unsigned int newcw, unsigned int mask)
    00047 {
    00048   int oldcw;
    00049   asm __volatile__
    00050   (
    00051         "       fclex                   \n"     // clear exceptions
    00052         "       fstcw   %3              \n"     // oldcw = FPU control word
    00053         "       andl    %3,%%eax        \n"     // eax &= oldcw;
    00054         "       andl    %0,%%ecx        \n"     // ecx &= newcw
    00055         "       orl     %%ecx,%%eax     \n"     // eax |= ecx
    00056         "       movl    %%eax,%3        \n"     // tmpcw = ebx
    00057         "       fldcw   %3              \n"     // load FPU control word
    00058         :
    00059         : "g" (newcw), "a" (~mask), "c" (mask), "m" (oldcw)
    00060         : "memory"
    00061   );
    00062   // NOTE: oldcw is modified by the asm.  workaround for gcc 3.0
    00063   return oldcw & 0xffff;
    00064 }
    00065
    00066
    00067 #else
    00068
    00069 #if defined(CS_COMPILER_MSVC)
    00070 #define csControl87     _control87
    00071 #else
    00072 static inline unsigned int csControl87(unsigned int, unsigned int) { return 0; }
    00073 #endif
    00074
    00075 #endif
    00076
    00077 #endif // __CS_FPU80X86_H__