| 1 |
/**************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* This file is part of Frama-C. */ |
| 4 |
/* */ |
| 5 |
/* Copyright (C) 2007-2022 */ |
| 6 |
/* CEA (Commissariat à l'énergie atomique et aux énergies */ |
| 7 |
/* alternatives) */ |
| 8 |
/* */ |
| 9 |
/* you can redistribute it and/or modify it under the terms of the GNU */ |
| 10 |
/* Lesser General Public License as published by the Free Software */ |
| 11 |
/* Foundation, version 2.1. */ |
| 12 |
/* */ |
| 13 |
/* It 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 */ |
| 16 |
/* GNU Lesser General Public License for more details. */ |
| 17 |
/* */ |
| 18 |
/* See the GNU Lesser General Public License version 2.1 */ |
| 19 |
/* for more details (enclosed in the file licenses/LGPLv2.1). */ |
| 20 |
/* */ |
| 21 |
/**************************************************************************/ |
| 22 |
|
| 23 |
/* ISO C: 7.6 */ |
| 24 |
#ifndef __FC_FENV |
| 25 |
#define __FC_FENV |
| 26 |
#include "features.h" |
| 27 |
__PUSH_FC_STDLIB |
| 28 |
|
| 29 |
__BEGIN_DECLS |
| 30 |
|
| 31 |
/* Define bits representing the exception. We use the bit positions |
| 32 |
of the appropriate bits in the FPU control word. */ |
| 33 |
enum __fc_fe_error |
| 34 |
{ |
| 35 |
FE_INVALID = 0x01, |
| 36 |
#define FE_INVALID FE_INVALID |
| 37 |
__FE_DENORM = 0x02, |
| 38 |
FE_DIVBYZERO = 0x04, |
| 39 |
#define FE_DIVBYZERO FE_DIVBYZERO |
| 40 |
FE_OVERFLOW = 0x08, |
| 41 |
#define FE_OVERFLOW FE_OVERFLOW |
| 42 |
FE_UNDERFLOW = 0x10, |
| 43 |
#define FE_UNDERFLOW FE_UNDERFLOW |
| 44 |
FE_INEXACT = 0x20 |
| 45 |
#define FE_INEXACT FE_INEXACT |
| 46 |
}; |
| 47 |
|
| 48 |
#define FE_ALL_EXCEPT \ |
| 49 |
(FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID) |
| 50 |
|
| 51 |
/* Type representing floating-point environment. This structure |
| 52 |
corresponds to the layout of the block written by the `fstenv' |
| 53 |
instruction and has additional fields for the contents of the MXCSR |
| 54 |
register as written by the `stmxcsr' instruction. */ |
| 55 |
typedef struct __fc_fenv_t |
| 56 |
{ |
| 57 |
unsigned short int __control_word; |
| 58 |
unsigned short int __unused1; |
| 59 |
unsigned short int __status_word; |
| 60 |
unsigned short int __unused2; |
| 61 |
unsigned short int __tags; |
| 62 |
unsigned short int __unused3; |
| 63 |
unsigned int __eip; |
| 64 |
unsigned short int __cs_selector; |
| 65 |
unsigned int __opcode:11; |
| 66 |
unsigned int __unused4:5; |
| 67 |
unsigned int __data_offset; |
| 68 |
unsigned short int __data_selector; |
| 69 |
unsigned short int __unused5; |
| 70 |
#ifdef __FC_MACHDEP_X86_64 /* only for x86_64 */ |
| 71 |
unsigned int __mxcsr; |
| 72 |
#endif |
| 73 |
} |
| 74 |
fenv_t; |
| 75 |
|
| 76 |
/** Determines which of a specified subset of the floating-point exception flags |
| 77 |
* are currently set. |
| 78 |
* \param excepts Specifies the floating-point status flags to be queried. |
| 79 |
* \return The value of the bitwise OR of the floating-point exception macros |
| 80 |
* corresponding to the currently set floating-point exceptions included in |
| 81 |
* parameter excepts. |
| 82 |
*/ |
| 83 |
extern int fetestexcept( int excepts ); |
| 84 |
|
| 85 |
/** Saves the current floating-point environment in the object pointed to by |
| 86 |
* envp, clears the floating-point status flags, and then installs a non-stop |
| 87 |
* (continue on floating-point exceptions) mode for all floating-point |
| 88 |
* exceptions. |
| 89 |
* \return Always returns zero. |
| 90 |
*/ |
| 91 |
extern int feholdexcept( fenv_t *envp ); |
| 92 |
|
| 93 |
/** Establishes the floating-point environment represented by the object pointed |
| 94 |
* to by envp. The argument envp shall point to a valid floating-point |
| 95 |
* environment object. |
| 96 |
* In principle, this function has the potential to trigger pending previous |
| 97 |
* exceptions: If envp contains a raised exception flag and at the same time |
| 98 |
* unmasks that exception type, then this will cause an interrupt. |
| 99 |
*/ |
| 100 |
extern int fesetenv( const fenv_t *envp ); |
| 101 |
|
| 102 |
/** Clears the supported floating-point exceptions represented by argument. |
| 103 |
*/ |
| 104 |
extern int feclearexcept( int excepts ); |
| 105 |
|
| 106 |
__END_DECLS |
| 107 |
|
| 108 |
__POP_FC_STDLIB |
| 109 |
#endif /* __FC_FENV */ |