]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/i386/sfp-exceptions.c
sfp-machine.h (__gcc_CMPtype, [...]): Move ...
[thirdparty/gcc.git] / libgcc / config / i386 / sfp-exceptions.c
CommitLineData
492fbea1
UB
1/*
2 * Copyright (C) 2012 Free Software Foundation, Inc.
3 *
4 * This file is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 3, or (at your option) any
7 * later version.
8 *
9 * This file is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * Under Section 7 of GPL version 3, you are granted additional
15 * permissions described in the GCC Runtime Library Exception, version
16 * 3.1, as published by the Free Software Foundation.
17 *
18 * You should have received a copy of the GNU General Public License and
19 * a copy of the GCC Runtime Library Exception along with this program;
20 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 * <http://www.gnu.org/licenses/>.
22 */
23
24#include "sfp-machine.h"
25
26struct fenv
27{
28 unsigned short int __control_word;
29 unsigned short int __unused1;
30 unsigned short int __status_word;
31 unsigned short int __unused2;
32 unsigned short int __tags;
33 unsigned short int __unused3;
34 unsigned int __eip;
35 unsigned short int __cs_selector;
36 unsigned int __opcode:11;
37 unsigned int __unused4:5;
38 unsigned int __data_offset;
39 unsigned short int __data_selector;
40 unsigned short int __unused5;
41};
42
43void
44__sfp_handle_exceptions (int _fex)
45{
46 if (_fex & FP_EX_INVALID)
47 {
48 float f = 0.0f;
49#ifdef __SSE__
50 asm volatile ("%vdivss\t{%0, %d0|%d0, %0}" : "+x" (f));
51#else
52 asm volatile ("fdiv\t{%y0, %0|%0, %y0}" : "+t" (f));
53 asm volatile ("fwait");
54#endif
55 }
56 if (_fex & FP_EX_DIVZERO)
57 {
58 float f = 1.0f, g = 0.0f;
59#ifdef __SSE__
60 asm volatile ("%vdivss\t{%1, %d0|%d0, %1}" : "+x" (f) : "xm" (g));
61#else
62 asm volatile ("fdivs\t%1" : "+t" (f) : "m" (g));
63 asm volatile ("fwait");
64#endif
65 }
66 if (_fex & FP_EX_OVERFLOW)
67 {
68 struct fenv temp;
69 asm volatile ("fnstenv\t%0" : "=m" (temp));
70 temp.__status_word |= FP_EX_OVERFLOW;
71 asm volatile ("fldenv\t%0" : : "m" (temp));
72 asm volatile ("fwait");
73 }
74 if (_fex & FP_EX_UNDERFLOW)
75 {
76 struct fenv temp;
77 asm volatile ("fnstenv\t%0" : "=m" (temp));
78 temp.__status_word |= FP_EX_UNDERFLOW;
79 asm volatile ("fldenv\t%0" : : "m" (temp));
80 asm volatile ("fwait");
81 }
82 if (_fex & FP_EX_INEXACT)
83 {
84 struct fenv temp;
85 asm volatile ("fnstenv\t%0" : "=m" (temp));
86 temp.__status_word |= FP_EX_INEXACT;
87 asm volatile ("fldenv\t%0" : : "m" (temp));
88 asm volatile ("fwait");
89 }
90};