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