Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / sysdeps / sparc / sparc64 / soft-fp / qp_util.c
1 /* Software floating-point emulation.
2    Helper routine for _Qp_* routines.
3    Simulate exceptions using double arithmetics.
4    Copyright (C) 1999-2013 Free Software Foundation, Inc.
5    This file is part of the GNU C Library.
6    Contributed by Jakub Jelinek (jj@ultra.linux.cz).
7
8    The GNU C Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public
10    License as published by the Free Software Foundation; either
11    version 2.1 of the License, or (at your option) any later version.
12
13    The GNU C Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the GNU C Library; if not, see
20    <http://www.gnu.org/licenses/>.  */
21
22 #include <float.h>
23 #include <math.h>
24 #include <assert.h>
25 #include "soft-fp.h"
26
27 void __Qp_handle_exceptions(int exceptions)
28 {
29   if (exceptions & FP_EX_INVALID)
30     {
31       float f = 0.0;
32       __asm__ __volatile__ ("fdivs %0, %0, %0" : "+f" (f));
33     }
34   if (exceptions & FP_EX_DIVZERO)
35     {
36       float f = 1.0, g = 0.0;
37       __asm__ __volatile__ ("fdivs %0, %1, %0"
38                             : "+f" (f)
39                             : "f" (g));
40     }
41   if (exceptions & FP_EX_OVERFLOW)
42     {
43       float f = FLT_MAX;
44       __asm__ __volatile__("fmuls %0, %0, %0" : "+f" (f));
45       exceptions &= ~FP_EX_INEXACT;
46     }
47   if (exceptions & FP_EX_UNDERFLOW)
48     {
49       float f = FLT_MIN;
50       __asm__ __volatile__("fmuls %0, %0, %0" : "+f" (f));
51       exceptions &= ~FP_EX_INEXACT;
52     }
53   if (exceptions & FP_EX_INEXACT)
54     {
55       double d = 1.0, e = M_PI;
56       __asm__ __volatile__ ("fdivd %0, %1, %0"
57                             : "+f" (d)
58                             : "f" (e));
59     }
60 }