1e34c47eaSAlex Bennée /* 2e34c47eaSAlex Bennée * QEMU float support - standalone helpers 3e34c47eaSAlex Bennée * 4e34c47eaSAlex Bennée * This is provided for files that don't need the access to the full 5e34c47eaSAlex Bennée * set of softfloat functions. Typically this is cpu initialisation 6e34c47eaSAlex Bennée * code which wants to set default rounding and exceptions modes. 7e34c47eaSAlex Bennée * 8e34c47eaSAlex Bennée * The code in this source file is derived from release 2a of the SoftFloat 9e34c47eaSAlex Bennée * IEC/IEEE Floating-point Arithmetic Package. Those parts of the code (and 10e34c47eaSAlex Bennée * some later contributions) are provided under that license, as detailed below. 11e34c47eaSAlex Bennée * It has subsequently been modified by contributors to the QEMU Project, 12e34c47eaSAlex Bennée * so some portions are provided under: 13e34c47eaSAlex Bennée * the SoftFloat-2a license 14e34c47eaSAlex Bennée * the BSD license 15e34c47eaSAlex Bennée * GPL-v2-or-later 16e34c47eaSAlex Bennée * 17e34c47eaSAlex Bennée * Any future contributions to this file after December 1st 2014 will be 18e34c47eaSAlex Bennée * taken to be licensed under the Softfloat-2a license unless specifically 19e34c47eaSAlex Bennée * indicated otherwise. 20e34c47eaSAlex Bennée */ 21e34c47eaSAlex Bennée 22e34c47eaSAlex Bennée /* 23e34c47eaSAlex Bennée =============================================================================== 24e34c47eaSAlex Bennée This C header file is part of the SoftFloat IEC/IEEE Floating-point 25e34c47eaSAlex Bennée Arithmetic Package, Release 2a. 26e34c47eaSAlex Bennée 27e34c47eaSAlex Bennée Written by John R. Hauser. This work was made possible in part by the 28e34c47eaSAlex Bennée International Computer Science Institute, located at Suite 600, 1947 Center 29e34c47eaSAlex Bennée Street, Berkeley, California 94704. Funding was partially provided by the 30e34c47eaSAlex Bennée National Science Foundation under grant MIP-9311980. The original version 31e34c47eaSAlex Bennée of this code was written as part of a project to build a fixed-point vector 32e34c47eaSAlex Bennée processor in collaboration with the University of California at Berkeley, 33e34c47eaSAlex Bennée overseen by Profs. Nelson Morgan and John Wawrzynek. More information 34e34c47eaSAlex Bennée is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ 35e34c47eaSAlex Bennée arithmetic/SoftFloat.html'. 36e34c47eaSAlex Bennée 37e34c47eaSAlex Bennée THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort 38e34c47eaSAlex Bennée has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT 39e34c47eaSAlex Bennée TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO 40e34c47eaSAlex Bennée PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 41e34c47eaSAlex Bennée AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 42e34c47eaSAlex Bennée 43e34c47eaSAlex Bennée Derivative works are acceptable, even for commercial purposes, so long as 44e34c47eaSAlex Bennée (1) they include prominent notice that the work is derivative, and (2) they 45e34c47eaSAlex Bennée include prominent notice akin to these four paragraphs for those parts of 46e34c47eaSAlex Bennée this code that are retained. 47e34c47eaSAlex Bennée 48e34c47eaSAlex Bennée =============================================================================== 49e34c47eaSAlex Bennée */ 50e34c47eaSAlex Bennée 51e52ee00dSAhmed Abouzied #ifndef SOFTFLOAT_HELPERS_H 52e52ee00dSAhmed Abouzied #define SOFTFLOAT_HELPERS_H 53e34c47eaSAlex Bennée 54e34c47eaSAlex Bennée #include "fpu/softfloat-types.h" 55e34c47eaSAlex Bennée 56a828b373SRichard Henderson static inline void set_float_detect_tininess(bool val, float_status *status) 57e34c47eaSAlex Bennée { 58a828b373SRichard Henderson status->tininess_before_rounding = val; 59e34c47eaSAlex Bennée } 60e34c47eaSAlex Bennée 613dede407SRichard Henderson static inline void set_float_rounding_mode(FloatRoundMode val, 623dede407SRichard Henderson float_status *status) 63e34c47eaSAlex Bennée { 64e34c47eaSAlex Bennée status->float_rounding_mode = val; 65e34c47eaSAlex Bennée } 66e34c47eaSAlex Bennée 67e34c47eaSAlex Bennée static inline void set_float_exception_flags(int val, float_status *status) 68e34c47eaSAlex Bennée { 69e34c47eaSAlex Bennée status->float_exception_flags = val; 70e34c47eaSAlex Bennée } 71e34c47eaSAlex Bennée 728da5f1dbSRichard Henderson static inline void set_floatx80_rounding_precision(FloatX80RoundPrec val, 73e34c47eaSAlex Bennée float_status *status) 74e34c47eaSAlex Bennée { 75e34c47eaSAlex Bennée status->floatx80_rounding_precision = val; 76e34c47eaSAlex Bennée } 77e34c47eaSAlex Bennée 788a132968SPeter Maydell static inline void set_float_2nan_prop_rule(Float2NaNPropRule rule, 798a132968SPeter Maydell float_status *status) 808a132968SPeter Maydell { 818a132968SPeter Maydell status->float_2nan_prop_rule = rule; 828a132968SPeter Maydell } 838a132968SPeter Maydell 84*7a944c30SPeter Maydell static inline void set_float_3nan_prop_rule(Float3NaNPropRule rule, 85*7a944c30SPeter Maydell float_status *status) 86*7a944c30SPeter Maydell { 87*7a944c30SPeter Maydell status->float_3nan_prop_rule = rule; 88*7a944c30SPeter Maydell } 89*7a944c30SPeter Maydell 904080eebdSPeter Maydell static inline void set_float_infzeronan_rule(FloatInfZeroNaNRule rule, 914080eebdSPeter Maydell float_status *status) 924080eebdSPeter Maydell { 934080eebdSPeter Maydell status->float_infzeronan_rule = rule; 944080eebdSPeter Maydell } 954080eebdSPeter Maydell 96c120391cSRichard Henderson static inline void set_flush_to_zero(bool val, float_status *status) 97e34c47eaSAlex Bennée { 98e34c47eaSAlex Bennée status->flush_to_zero = val; 99e34c47eaSAlex Bennée } 100e34c47eaSAlex Bennée 101c120391cSRichard Henderson static inline void set_flush_inputs_to_zero(bool val, float_status *status) 102e34c47eaSAlex Bennée { 103e34c47eaSAlex Bennée status->flush_inputs_to_zero = val; 104e34c47eaSAlex Bennée } 105e34c47eaSAlex Bennée 106c120391cSRichard Henderson static inline void set_default_nan_mode(bool val, float_status *status) 107e34c47eaSAlex Bennée { 108e34c47eaSAlex Bennée status->default_nan_mode = val; 109e34c47eaSAlex Bennée } 110e34c47eaSAlex Bennée 111c120391cSRichard Henderson static inline void set_snan_bit_is_one(bool val, float_status *status) 112e34c47eaSAlex Bennée { 113e34c47eaSAlex Bennée status->snan_bit_is_one = val; 114e34c47eaSAlex Bennée } 115e34c47eaSAlex Bennée 116913602e3SMax Filippov static inline void set_use_first_nan(bool val, float_status *status) 117913602e3SMax Filippov { 118913602e3SMax Filippov status->use_first_nan = val; 119913602e3SMax Filippov } 120913602e3SMax Filippov 121cc43c692SMax Filippov static inline void set_no_signaling_nans(bool val, float_status *status) 122cc43c692SMax Filippov { 123cc43c692SMax Filippov status->no_signaling_nans = val; 124cc43c692SMax Filippov } 125cc43c692SMax Filippov 126a828b373SRichard Henderson static inline bool get_float_detect_tininess(float_status *status) 127e34c47eaSAlex Bennée { 128a828b373SRichard Henderson return status->tininess_before_rounding; 129e34c47eaSAlex Bennée } 130e34c47eaSAlex Bennée 1313dede407SRichard Henderson static inline FloatRoundMode get_float_rounding_mode(float_status *status) 132e34c47eaSAlex Bennée { 133e34c47eaSAlex Bennée return status->float_rounding_mode; 134e34c47eaSAlex Bennée } 135e34c47eaSAlex Bennée 136e34c47eaSAlex Bennée static inline int get_float_exception_flags(float_status *status) 137e34c47eaSAlex Bennée { 138e34c47eaSAlex Bennée return status->float_exception_flags; 139e34c47eaSAlex Bennée } 140e34c47eaSAlex Bennée 1418da5f1dbSRichard Henderson static inline FloatX80RoundPrec 1428da5f1dbSRichard Henderson get_floatx80_rounding_precision(float_status *status) 143e34c47eaSAlex Bennée { 144e34c47eaSAlex Bennée return status->floatx80_rounding_precision; 145e34c47eaSAlex Bennée } 146e34c47eaSAlex Bennée 1478a132968SPeter Maydell static inline Float2NaNPropRule get_float_2nan_prop_rule(float_status *status) 1488a132968SPeter Maydell { 1498a132968SPeter Maydell return status->float_2nan_prop_rule; 1508a132968SPeter Maydell } 1518a132968SPeter Maydell 152*7a944c30SPeter Maydell static inline Float3NaNPropRule get_float_3nan_prop_rule(float_status *status) 153*7a944c30SPeter Maydell { 154*7a944c30SPeter Maydell return status->float_3nan_prop_rule; 155*7a944c30SPeter Maydell } 156*7a944c30SPeter Maydell 1574080eebdSPeter Maydell static inline FloatInfZeroNaNRule get_float_infzeronan_rule(float_status *status) 1584080eebdSPeter Maydell { 1594080eebdSPeter Maydell return status->float_infzeronan_rule; 1604080eebdSPeter Maydell } 1614080eebdSPeter Maydell 162c120391cSRichard Henderson static inline bool get_flush_to_zero(float_status *status) 163e34c47eaSAlex Bennée { 164e34c47eaSAlex Bennée return status->flush_to_zero; 165e34c47eaSAlex Bennée } 166e34c47eaSAlex Bennée 167c120391cSRichard Henderson static inline bool get_flush_inputs_to_zero(float_status *status) 168e34c47eaSAlex Bennée { 169e34c47eaSAlex Bennée return status->flush_inputs_to_zero; 170e34c47eaSAlex Bennée } 171e34c47eaSAlex Bennée 172c120391cSRichard Henderson static inline bool get_default_nan_mode(float_status *status) 173e34c47eaSAlex Bennée { 174e34c47eaSAlex Bennée return status->default_nan_mode; 175e34c47eaSAlex Bennée } 176e34c47eaSAlex Bennée 177ea9cea93SMarkus Armbruster #endif /* SOFTFLOAT_HELPERS_H */ 178