2000-10-15 05:36:03 +02:00
|
|
|
/* Raise given exceptions.
|
2002-09-10 03:26:37 +02:00
|
|
|
Copyright (C) 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
|
2000-10-15 05:36:03 +02:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by David Huggins-Daines <dhd@debian.org>
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 06:56:23 +02:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2000-10-15 05:36:03 +02:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 06:56:23 +02:00
|
|
|
Lesser General Public License for more details.
|
2000-10-15 05:36:03 +02:00
|
|
|
|
2001-07-06 06:56:23 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-03-10 00:56:38 +01:00
|
|
|
License along with the GNU C Library. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2000-10-15 05:36:03 +02:00
|
|
|
|
|
|
|
#include <fenv.h>
|
2001-01-31 07:34:29 +01:00
|
|
|
#include <float.h>
|
2000-10-15 05:36:03 +02:00
|
|
|
#include <math.h>
|
|
|
|
|
2003-12-18 04:58:09 +01:00
|
|
|
/* Please see section 10,
|
|
|
|
page 10-5 "Delayed Trapping" in the PA-RISC 2.0 Architecture manual */
|
|
|
|
|
2000-10-15 05:36:03 +02:00
|
|
|
int
|
|
|
|
feraiseexcept (int excepts)
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
|
exception. */
|
|
|
|
|
|
|
|
/* We do these bits in assembly to be certain GCC doesn't optimize
|
|
|
|
away something important, and so we can force delayed traps to
|
2003-12-18 04:58:09 +01:00
|
|
|
occur. */
|
2000-10-15 05:36:03 +02:00
|
|
|
|
2003-12-18 04:58:09 +01:00
|
|
|
/* We use "fldd 0(%%sr0,%%sp),%0" to flush the delayed exception */
|
|
|
|
|
|
|
|
/* First: Invalid exception. */
|
2000-10-15 05:36:03 +02:00
|
|
|
if (excepts & FE_INVALID)
|
|
|
|
{
|
|
|
|
/* One example of a invalid operation is 0 * Infinity. */
|
|
|
|
double d = HUGE_VAL;
|
2003-12-18 04:58:09 +01:00
|
|
|
__asm__ __volatile__ (
|
|
|
|
" fcpy,dbl %%fr0,%%fr22\n"
|
|
|
|
" fmpy,dbl %0,%%fr22,%0\n"
|
|
|
|
" fldd 0(%%sr0,%%sp),%0"
|
|
|
|
: "+f" (d) : : "%fr22" );
|
2000-10-15 05:36:03 +02:00
|
|
|
}
|
|
|
|
|
2003-12-18 04:58:09 +01:00
|
|
|
/* Second: Division by zero. */
|
2000-10-15 05:36:03 +02:00
|
|
|
if (excepts & FE_DIVBYZERO)
|
|
|
|
{
|
|
|
|
double d = 1.0;
|
2003-12-18 04:58:09 +01:00
|
|
|
__asm__ __volatile__ (
|
|
|
|
" fcpy,dbl %%fr0,%%fr22\n"
|
|
|
|
" fdiv,dbl %0,%%fr22,%0\n"
|
|
|
|
" fldd 0(%%sr0,%%sp),%0"
|
|
|
|
: "+f" (d) : : "%fr22" );
|
2000-10-15 05:36:03 +02:00
|
|
|
}
|
|
|
|
|
2003-12-18 04:58:09 +01:00
|
|
|
/* Third: Overflow. */
|
2000-10-15 05:36:03 +02:00
|
|
|
if (excepts & FE_OVERFLOW)
|
|
|
|
{
|
|
|
|
double d = DBL_MAX;
|
2003-12-18 04:58:09 +01:00
|
|
|
__asm__ __volatile__ (
|
|
|
|
" fadd,dbl %0,%0,%0\n"
|
|
|
|
" fldd 0(%%sr0,%%sp),%0"
|
|
|
|
: "+f" (d) );
|
2000-10-15 05:36:03 +02:00
|
|
|
}
|
|
|
|
|
2003-12-18 04:58:09 +01:00
|
|
|
/* Fourth: Underflow. */
|
2000-10-15 05:36:03 +02:00
|
|
|
if (excepts & FE_UNDERFLOW)
|
|
|
|
{
|
|
|
|
double d = DBL_MIN;
|
2003-12-18 04:58:09 +01:00
|
|
|
double e = 3.0;
|
|
|
|
__asm__ __volatile__ (
|
|
|
|
" fdiv,dbl %0,%1,%0\n"
|
|
|
|
" fldd 0(%%sr0,%%sp),%0"
|
|
|
|
: "+f" (d) : "f" (e) );
|
2000-10-15 05:36:03 +02:00
|
|
|
}
|
|
|
|
|
2003-12-18 04:58:09 +01:00
|
|
|
/* Fifth: Inexact */
|
2000-10-15 05:36:03 +02:00
|
|
|
if (excepts & FE_INEXACT)
|
|
|
|
{
|
2003-12-18 04:58:09 +01:00
|
|
|
double d = M_PI;
|
|
|
|
double e = 69.69;
|
|
|
|
__asm__ __volatile__ (
|
|
|
|
" fdiv,dbl %0,%1,%%fr22\n"
|
|
|
|
" fcnvfxt,dbl,sgl %%fr22,%%fr22L\n"
|
|
|
|
" fldd 0(%%sr0,%%sp),%%fr22"
|
|
|
|
: : "f" (d), "f" (e) : "%fr22" );
|
2000-10-15 05:36:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Success. */
|
|
|
|
return 0;
|
|
|
|
}
|
2002-09-10 03:26:37 +02:00
|
|
|
libm_hidden_def (feraiseexcept)
|