| 1 | /* |
| 2 | * QEMU float support - standalone helpers |
| 3 | * |
| 4 | * This is provided for files that don't need the access to the full |
| 5 | * set of softfloat functions. Typically this is cpu initialisation |
| 6 | * code which wants to set default rounding and exceptions modes. |
| 7 | * |
| 8 | * The code in this source file is derived from release 2a of the SoftFloat |
| 9 | * IEC/IEEE Floating-point Arithmetic Package. Those parts of the code (and |
| 10 | * some later contributions) are provided under that license, as detailed below. |
| 11 | * It has subsequently been modified by contributors to the QEMU Project, |
| 12 | * so some portions are provided under: |
| 13 | * the SoftFloat-2a license |
| 14 | * the BSD license |
| 15 | * GPL-v2-or-later |
| 16 | * |
| 17 | * Any future contributions to this file after December 1st 2014 will be |
| 18 | * taken to be licensed under the Softfloat-2a license unless specifically |
| 19 | * indicated otherwise. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | =============================================================================== |
| 24 | This C header file is part of the SoftFloat IEC/IEEE Floating-point |
| 25 | Arithmetic Package, Release 2a. |
| 26 | |
| 27 | Written by John R. Hauser. This work was made possible in part by the |
| 28 | International Computer Science Institute, located at Suite 600, 1947 Center |
| 29 | Street, Berkeley, California 94704. Funding was partially provided by the |
| 30 | National Science Foundation under grant MIP-9311980. The original version |
| 31 | of this code was written as part of a project to build a fixed-point vector |
| 32 | processor in collaboration with the University of California at Berkeley, |
| 33 | overseen by Profs. Nelson Morgan and John Wawrzynek. More information |
| 34 | is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ |
| 35 | arithmetic/SoftFloat.html'. |
| 36 | |
| 37 | THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort |
| 38 | has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT |
| 39 | TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO |
| 40 | PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY |
| 41 | AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. |
| 42 | |
| 43 | Derivative works are acceptable, even for commercial purposes, so long as |
| 44 | (1) they include prominent notice that the work is derivative, and (2) they |
| 45 | include prominent notice akin to these four paragraphs for those parts of |
| 46 | this code that are retained. |
| 47 | |
| 48 | =============================================================================== |
| 49 | */ |
| 50 | |
| 51 | #ifndef SOFTFLOAT_HELPERS_H |
| 52 | #define SOFTFLOAT_HELPERS_H |
| 53 | |
| 54 | #include "fpu/softfloat-types.h" |
| 55 | |
| 56 | static inline void set_float_detect_tininess(bool val, float_status *status) |
| 57 | { |
| 58 | status->tininess_before_rounding = val; |
| 59 | } |
| 60 | |
| 61 | static inline void set_float_rounding_mode(FloatRoundMode val, |
| 62 | float_status *status) |
| 63 | { |
| 64 | status->float_rounding_mode = val; |
| 65 | } |
| 66 | |
| 67 | static inline void |
| 68 | set_float_exception_flags(FloatExceptionFlags val, float_status *status) |
| 69 | { |
| 70 | status->float_exception_flags = val; |
| 71 | } |
| 72 | |
| 73 | static inline void set_floatx80_rounding_precision(FloatX80RoundPrec val, |
| 74 | float_status *status) |
| 75 | { |
| 76 | status->floatx80_rounding_precision = val; |
| 77 | } |
| 78 | |
| 79 | static inline void set_floatx80_behaviour(FloatX80Behaviour b, |
| 80 | float_status *status) |
| 81 | { |
| 82 | status->floatx80_behaviour = b; |
| 83 | } |
| 84 | |
| 85 | static inline void set_float_2nan_prop_rule(Float2NaNPropRule rule, |
| 86 | float_status *status) |
| 87 | { |
| 88 | status->float_2nan_prop_rule = rule; |
| 89 | } |
| 90 | |
| 91 | static inline void set_float_3nan_prop_rule(Float3NaNPropRule rule, |
| 92 | float_status *status) |
| 93 | { |
| 94 | status->float_3nan_prop_rule = rule; |
| 95 | } |
| 96 | |
| 97 | static inline void set_float_infzeronan_rule(FloatInfZeroNaNRule rule, |
| 98 | float_status *status) |
| 99 | { |
| 100 | status->float_infzeronan_rule = rule; |
| 101 | } |
| 102 | |
| 103 | static inline void set_float_default_nan_pattern(uint8_t dnan_pattern, |
| 104 | float_status *status) |
| 105 | { |
| 106 | status->default_nan_pattern = dnan_pattern; |
| 107 | } |
| 108 | |
| 109 | static inline void set_flush_to_zero(bool val, float_status *status) |
| 110 | { |
| 111 | status->flush_to_zero = val; |
| 112 | } |
| 113 | |
| 114 | static inline void set_flush_inputs_to_zero(bool val, float_status *status) |
| 115 | { |
| 116 | status->flush_inputs_to_zero = val; |
| 117 | } |
| 118 | |
| 119 | static inline void set_float_ftz_detection(bool val, float_status *status) |
| 120 | { |
| 121 | status->ftz_before_rounding = val; |
| 122 | } |
| 123 | |
| 124 | static inline void set_default_nan_mode(bool val, float_status *status) |
| 125 | { |
| 126 | status->default_nan_mode = val; |
| 127 | } |
| 128 | |
| 129 | static inline void set_snan_rule(FloatSNaNRule val, float_status *status) |
| 130 | { |
| 131 | status->float_snan_rule = val; |
| 132 | } |
| 133 | |
| 134 | static inline void set_float_e4m3_nan_is_snan(bool val, float_status *status) |
| 135 | { |
| 136 | status->e4m3_nan_is_snan = val; |
| 137 | } |
| 138 | |
| 139 | static inline void set_float_rebias_overflow(bool val, float_status *status) |
| 140 | { |
| 141 | status->rebias_overflow = val; |
| 142 | } |
| 143 | |
| 144 | static inline void set_float_rebias_underflow(bool val, float_status *status) |
| 145 | { |
| 146 | status->rebias_underflow = val; |
| 147 | } |
| 148 | |
| 149 | static inline FloatRoundMode get_float_rounding_mode(const float_status *status) |
| 150 | { |
| 151 | return status->float_rounding_mode; |
| 152 | } |
| 153 | |
| 154 | static inline FloatExceptionFlags |
| 155 | get_float_exception_flags(const float_status *status) |
| 156 | { |
| 157 | return status->float_exception_flags; |
| 158 | } |
| 159 | |
| 160 | static inline FloatX80RoundPrec |
| 161 | get_floatx80_rounding_precision(const float_status *status) |
| 162 | { |
| 163 | return status->floatx80_rounding_precision; |
| 164 | } |
| 165 | |
| 166 | static inline FloatX80Behaviour |
| 167 | get_floatx80_behaviour(const float_status *status) |
| 168 | { |
| 169 | return status->floatx80_behaviour; |
| 170 | } |
| 171 | |
| 172 | static inline Float2NaNPropRule |
| 173 | get_float_2nan_prop_rule(const float_status *status) |
| 174 | { |
| 175 | return status->float_2nan_prop_rule; |
| 176 | } |
| 177 | |
| 178 | static inline Float3NaNPropRule |
| 179 | get_float_3nan_prop_rule(const float_status *status) |
| 180 | { |
| 181 | return status->float_3nan_prop_rule; |
| 182 | } |
| 183 | |
| 184 | static inline FloatInfZeroNaNRule |
| 185 | get_float_infzeronan_rule(const float_status *status) |
| 186 | { |
| 187 | return status->float_infzeronan_rule; |
| 188 | } |
| 189 | |
| 190 | static inline bool get_flush_to_zero(const float_status *status) |
| 191 | { |
| 192 | return status->flush_to_zero; |
| 193 | } |
| 194 | |
| 195 | static inline bool get_flush_inputs_to_zero(const float_status *status) |
| 196 | { |
| 197 | return status->flush_inputs_to_zero; |
| 198 | } |
| 199 | |
| 200 | static inline bool get_default_nan_mode(const float_status *status) |
| 201 | { |
| 202 | return status->default_nan_mode; |
| 203 | } |
| 204 | |
| 205 | static inline FloatSNaNRule get_snan_rule(float_status *status) |
| 206 | { |
| 207 | return status->float_snan_rule; |
| 208 | } |
| 209 | |
| 210 | #endif /* SOFTFLOAT_HELPERS_H */ |