Back to index

glibc  2.9
fraiseexcpt.c
Go to the documentation of this file.
00001 /* Copyright (C) 2004,2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C 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    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <fenv_libc.h>
00020 #include <sysdep.h>
00021 #include <float.h>
00022 #include <kernel-features.h>
00023 #include "kernel_sysinfo.h"
00024 
00025 
00026 int
00027 __feraiseexcept (int excepts)
00028 {
00029   INTERNAL_SYSCALL_DECL (err);
00030   unsigned long t = excepts;
00031   long r;
00032 
00033   r = INTERNAL_SYSCALL (osf_setsysinfo, err, 2, SSI_IEEE_RAISE_EXCEPTION, &t);
00034 
00035 #ifndef __ASSUME_IEEE_RAISE_EXCEPTION
00036   if (!INTERNAL_SYSCALL_ERROR_P (r, err))
00037     return 0;
00038 
00039   double d;
00040 
00041   /* If we got an error from SSI_IEEE_RAISE_EXCEPTION, assume it means that
00042      the system call isn't actually implemented.  Do the best we can.  */
00043 
00044   /* Invalid implemented with 0 / 0 -> NaN.  */
00045   if (excepts & FE_INVALID)
00046     __asm__ __volatile__ ("divs/su $f31,$f31,%0; trapb" : "=f"(d) : );
00047 
00048   /* Division By Zero implemented with 1 / 0 -> NaN.  */
00049   if (excepts & FE_DIVBYZERO)
00050     __asm__ __volatile__ ("divs/su %1,$f31,%0; trapb" : "=&f"(d) : "f"(1.0f));
00051 
00052   /* Overflow and underflow cannot be had all by themselves.  We can
00053      generate them with arithmetic, but we always get INEXACT raised
00054      at the same time.  Prepare to undo.  */
00055   if ((excepts & (FE_OVERFLOW | FE_UNDERFLOW)) && !(excepts & FE_INEXACT))
00056     INTERNAL_SYSCALL (osf_getsysinfo, err, 2, GSI_IEEE_FP_CONTROL, &t);
00057 
00058   /* Overflow implemented with FLT_MAX + FLT_MAX -> Inf.  */
00059   if (excepts & FE_OVERFLOW)
00060     __asm__ __volatile__ ("adds/sui %1,%1,%0; trapb"
00061                        : "=&f"(d) : "f"(FLT_MAX));
00062 
00063   /* Underflow implemented with FLT_MIN * FLT_MIN -> 0.  */
00064   if (excepts & FE_UNDERFLOW)
00065     __asm__ __volatile__ ("muls/sui %1,%1,%0; trapb"
00066                        : "=&f"(d) : "f"(FLT_MIN));
00067 
00068   /* Inexact implemented with (long)0.5 -> 0.  */
00069   if ((excepts & (FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)) == FE_INEXACT)
00070     __asm__ __volatile__ ("cvttq/svi %1,%0; trapb" : "=&f"(d) : "f"(0.5f));
00071 
00072   /* If we raised inexact when not asked, and inexact was not previously
00073      raised, then clear that exception.  */
00074   if ((excepts & (FE_OVERFLOW | FE_UNDERFLOW))
00075       && !((excepts | t) & FE_INEXACT))
00076     {
00077       t |= excepts & SWCR_STATUS_MASK;
00078       INTERNAL_SYSCALL (osf_setsysinfo, err, 2, SSI_IEEE_FP_CONTROL, &t);
00079     }
00080 #endif /* !__ASSUME_IEEE_RAISE_EXCEPTION */
00081 
00082   return 0;
00083 }
00084 
00085 #include <shlib-compat.h>
00086 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
00087 strong_alias (__feraiseexcept, __old_feraiseexcept)
00088 compat_symbol (libm, __old_feraiseexcept, feraiseexcept, GLIBC_2_1);
00089 #endif
00090 
00091 libm_hidden_ver (__feraiseexcept, feraiseexcept)
00092 versioned_symbol (libm, __feraiseexcept, feraiseexcept, GLIBC_2_2);