hppa: Export main in pr104869.C on hpux
[official-gcc.git] / libatomic / config / x86 / fenv.c
blob03e1c2d7207f8c9fbbd59bedff51cccbe0d7ed9d
1 /* Copyright (C) 2013-2023 Free Software Foundation, Inc.
3 This file is part of the GNU Atomic Library (libatomic).
5 Libatomic is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
24 #include "libatomic_i.h"
26 #define FE_INVALID 0x01
27 #define FE_DENORM 0x02
28 #define FE_DIVBYZERO 0x04
29 #define FE_OVERFLOW 0x08
30 #define FE_UNDERFLOW 0x10
31 #define FE_INEXACT 0x20
33 struct fenv
35 unsigned short int __control_word;
36 unsigned short int __unused1;
37 unsigned short int __status_word;
38 unsigned short int __unused2;
39 unsigned short int __tags;
40 unsigned short int __unused3;
41 unsigned int __eip;
42 unsigned short int __cs_selector;
43 unsigned int __opcode:11;
44 unsigned int __unused4:5;
45 unsigned int __data_offset;
46 unsigned short int __data_selector;
47 unsigned short int __unused5;
48 } __attribute__ ((gcc_struct));
50 #ifdef __SSE_MATH__
51 # define __math_force_eval_div(x, y) \
52 do { asm ("" : "+x" (x)); asm volatile ("" : : "x" (x / y)); } while (0)
53 #else
54 # define __math_force_eval_div(x, y) \
55 do { asm ("" : "+t" (x)); asm volatile ("" : : "f" (x / y)); } while (0)
56 #endif
58 /* Raise the supported floating-point exceptions from EXCEPTS. Other
59 bits in EXCEPTS are ignored. */
61 void
62 __atomic_feraiseexcept (int excepts)
64 struct fenv temp;
66 if (excepts & FE_INVALID)
68 float f = 0.0f;
69 __math_force_eval_div (f, f);
71 if (excepts & FE_DENORM)
73 asm volatile ("fnstenv\t%0" : "=m" (temp));
74 temp.__status_word |= FE_DENORM;
75 asm volatile ("fldenv\t%0" : : "m" (temp));
76 asm volatile ("fwait");
78 if (excepts & FE_DIVBYZERO)
80 float f = 1.0f, g = 0.0f;
81 __math_force_eval_div (f, g);
83 if (excepts & FE_OVERFLOW)
85 asm volatile ("fnstenv\t%0" : "=m" (temp));
86 temp.__status_word |= FE_OVERFLOW;
87 asm volatile ("fldenv\t%0" : : "m" (temp));
88 asm volatile ("fwait");
90 if (excepts & FE_UNDERFLOW)
92 asm volatile ("fnstenv\t%0" : "=m" (temp));
93 temp.__status_word |= FE_UNDERFLOW;
94 asm volatile ("fldenv\t%0" : : "m" (temp));
95 asm volatile ("fwait");
97 if (excepts & FE_INEXACT)
99 float f = 1.0f, g = 3.0f;
100 __math_force_eval_div (f, g);