Back to index

glibc  2.9
fraiseexcpt.c File Reference
#include <fenv.h>
#include <float.h>
#include <math.h>

Go to the source code of this file.


int feraiseexcept (int excepts)

Function Documentation

int feraiseexcept ( int  excepts)

Definition at line 25 of file fraiseexcpt.c.

  /* Raise exceptions represented by EXCEPTS.  But we must raise only one
     signal at a time.  It is important that if the overflow/underflow
     exception and the divide by zero exception are given at the same
     time, the overflow/underflow exception follows the divide by zero

     The Coldfire FPU allows an exception to be raised by asserting
     the associated EXC bit and then executing an arbitrary arithmetic
     instruction.  fmove.l is classified as an arithmetic instruction
     and suffices for this purpose.

     We therefore raise an exception by setting both the EXC and AEXC
     bit associated with the exception (the former being 6 bits to the
     left of the latter) and then loading the longword at (%sp) into an
     FP register.  */

  inline void
  raise_one_exception (int mask)
    if (excepts & mask)
       int fpsr;
       double unused;

       asm volatile ("fmove%.l %/fpsr,%0" : "=d" (fpsr));
       fpsr |= (mask << 6) | mask;
       asm volatile ("fmove%.l %0,%/fpsr" :: "d" (fpsr));
       asm volatile ("fmove%.l (%%sp),%0" : "=f" (unused));

  raise_one_exception (FE_INVALID);
  raise_one_exception (FE_DIVBYZERO);
  raise_one_exception (FE_OVERFLOW);
  raise_one_exception (FE_UNDERFLOW);
  raise_one_exception (FE_INEXACT);

  /* Success.  */
  return 0;