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
set_float_detect_tininess(bool val,float_status * status)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
set_float_rounding_mode(FloatRoundMode val,float_status * status)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
set_float_exception_flags(int val,float_status * status)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
set_floatx80_rounding_precision(FloatX80RoundPrec val,float_status * status)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
set_floatx80_behaviour(FloatX80Behaviour b,float_status * status)78*9b6e986eSPeter Maydell static inline void set_floatx80_behaviour(FloatX80Behaviour b,
79*9b6e986eSPeter Maydell float_status *status)
80*9b6e986eSPeter Maydell {
81*9b6e986eSPeter Maydell status->floatx80_behaviour = b;
82*9b6e986eSPeter Maydell }
83*9b6e986eSPeter Maydell
set_float_2nan_prop_rule(Float2NaNPropRule rule,float_status * status)848a132968SPeter Maydell static inline void set_float_2nan_prop_rule(Float2NaNPropRule rule,
858a132968SPeter Maydell float_status *status)
868a132968SPeter Maydell {
878a132968SPeter Maydell status->float_2nan_prop_rule = rule;
888a132968SPeter Maydell }
898a132968SPeter Maydell
set_float_3nan_prop_rule(Float3NaNPropRule rule,float_status * status)907a944c30SPeter Maydell static inline void set_float_3nan_prop_rule(Float3NaNPropRule rule,
917a944c30SPeter Maydell float_status *status)
927a944c30SPeter Maydell {
937a944c30SPeter Maydell status->float_3nan_prop_rule = rule;
947a944c30SPeter Maydell }
957a944c30SPeter Maydell
set_float_infzeronan_rule(FloatInfZeroNaNRule rule,float_status * status)964080eebdSPeter Maydell static inline void set_float_infzeronan_rule(FloatInfZeroNaNRule rule,
974080eebdSPeter Maydell float_status *status)
984080eebdSPeter Maydell {
994080eebdSPeter Maydell status->float_infzeronan_rule = rule;
1004080eebdSPeter Maydell }
1014080eebdSPeter Maydell
set_float_default_nan_pattern(uint8_t dnan_pattern,float_status * status)1021b2de0c3SPeter Maydell static inline void set_float_default_nan_pattern(uint8_t dnan_pattern,
1031b2de0c3SPeter Maydell float_status *status)
1041b2de0c3SPeter Maydell {
1051b2de0c3SPeter Maydell status->default_nan_pattern = dnan_pattern;
1061b2de0c3SPeter Maydell }
1071b2de0c3SPeter Maydell
set_flush_to_zero(bool val,float_status * status)108c120391cSRichard Henderson static inline void set_flush_to_zero(bool val, float_status *status)
109e34c47eaSAlex Bennée {
110e34c47eaSAlex Bennée status->flush_to_zero = val;
111e34c47eaSAlex Bennée }
112e34c47eaSAlex Bennée
set_flush_inputs_to_zero(bool val,float_status * status)113c120391cSRichard Henderson static inline void set_flush_inputs_to_zero(bool val, float_status *status)
114e34c47eaSAlex Bennée {
115e34c47eaSAlex Bennée status->flush_inputs_to_zero = val;
116e34c47eaSAlex Bennée }
117e34c47eaSAlex Bennée
set_float_ftz_detection(FloatFTZDetection d,float_status * status)11828f13bccSPeter Maydell static inline void set_float_ftz_detection(FloatFTZDetection d,
11928f13bccSPeter Maydell float_status *status)
12028f13bccSPeter Maydell {
12128f13bccSPeter Maydell status->ftz_detection = d;
12228f13bccSPeter Maydell }
12328f13bccSPeter Maydell
set_default_nan_mode(bool val,float_status * status)124c120391cSRichard Henderson static inline void set_default_nan_mode(bool val, float_status *status)
125e34c47eaSAlex Bennée {
126e34c47eaSAlex Bennée status->default_nan_mode = val;
127e34c47eaSAlex Bennée }
128e34c47eaSAlex Bennée
set_snan_bit_is_one(bool val,float_status * status)129c120391cSRichard Henderson static inline void set_snan_bit_is_one(bool val, float_status *status)
130e34c47eaSAlex Bennée {
131e34c47eaSAlex Bennée status->snan_bit_is_one = val;
132e34c47eaSAlex Bennée }
133e34c47eaSAlex Bennée
set_no_signaling_nans(bool val,float_status * status)134cc43c692SMax Filippov static inline void set_no_signaling_nans(bool val, float_status *status)
135cc43c692SMax Filippov {
136cc43c692SMax Filippov status->no_signaling_nans = val;
137cc43c692SMax Filippov }
138cc43c692SMax Filippov
get_float_detect_tininess(const float_status * status)139db164982SPhilippe Mathieu-Daudé static inline bool get_float_detect_tininess(const float_status *status)
140e34c47eaSAlex Bennée {
141a828b373SRichard Henderson return status->tininess_before_rounding;
142e34c47eaSAlex Bennée }
143e34c47eaSAlex Bennée
get_float_rounding_mode(const float_status * status)144db164982SPhilippe Mathieu-Daudé static inline FloatRoundMode get_float_rounding_mode(const float_status *status)
145e34c47eaSAlex Bennée {
146e34c47eaSAlex Bennée return status->float_rounding_mode;
147e34c47eaSAlex Bennée }
148e34c47eaSAlex Bennée
get_float_exception_flags(const float_status * status)149db164982SPhilippe Mathieu-Daudé static inline int get_float_exception_flags(const float_status *status)
150e34c47eaSAlex Bennée {
151e34c47eaSAlex Bennée return status->float_exception_flags;
152e34c47eaSAlex Bennée }
153e34c47eaSAlex Bennée
1548da5f1dbSRichard Henderson static inline FloatX80RoundPrec
get_floatx80_rounding_precision(const float_status * status)155db164982SPhilippe Mathieu-Daudé get_floatx80_rounding_precision(const float_status *status)
156e34c47eaSAlex Bennée {
157e34c47eaSAlex Bennée return status->floatx80_rounding_precision;
158e34c47eaSAlex Bennée }
159e34c47eaSAlex Bennée
160*9b6e986eSPeter Maydell static inline FloatX80Behaviour
get_floatx80_behaviour(const float_status * status)161*9b6e986eSPeter Maydell get_floatx80_behaviour(const float_status *status)
162*9b6e986eSPeter Maydell {
163*9b6e986eSPeter Maydell return status->floatx80_behaviour;
164*9b6e986eSPeter Maydell }
165*9b6e986eSPeter Maydell
166db164982SPhilippe Mathieu-Daudé static inline Float2NaNPropRule
get_float_2nan_prop_rule(const float_status * status)167db164982SPhilippe Mathieu-Daudé get_float_2nan_prop_rule(const float_status *status)
1688a132968SPeter Maydell {
1698a132968SPeter Maydell return status->float_2nan_prop_rule;
1708a132968SPeter Maydell }
1718a132968SPeter Maydell
172db164982SPhilippe Mathieu-Daudé static inline Float3NaNPropRule
get_float_3nan_prop_rule(const float_status * status)173db164982SPhilippe Mathieu-Daudé get_float_3nan_prop_rule(const float_status *status)
1747a944c30SPeter Maydell {
1757a944c30SPeter Maydell return status->float_3nan_prop_rule;
1767a944c30SPeter Maydell }
1777a944c30SPeter Maydell
178db164982SPhilippe Mathieu-Daudé static inline FloatInfZeroNaNRule
get_float_infzeronan_rule(const float_status * status)179db164982SPhilippe Mathieu-Daudé get_float_infzeronan_rule(const float_status *status)
1804080eebdSPeter Maydell {
1814080eebdSPeter Maydell return status->float_infzeronan_rule;
1824080eebdSPeter Maydell }
1834080eebdSPeter Maydell
get_float_default_nan_pattern(const float_status * status)184db164982SPhilippe Mathieu-Daudé static inline uint8_t get_float_default_nan_pattern(const float_status *status)
1851b2de0c3SPeter Maydell {
1861b2de0c3SPeter Maydell return status->default_nan_pattern;
1871b2de0c3SPeter Maydell }
1881b2de0c3SPeter Maydell
get_flush_to_zero(const float_status * status)189db164982SPhilippe Mathieu-Daudé static inline bool get_flush_to_zero(const float_status *status)
190e34c47eaSAlex Bennée {
191e34c47eaSAlex Bennée return status->flush_to_zero;
192e34c47eaSAlex Bennée }
193e34c47eaSAlex Bennée
get_flush_inputs_to_zero(const float_status * status)194db164982SPhilippe Mathieu-Daudé static inline bool get_flush_inputs_to_zero(const float_status *status)
195e34c47eaSAlex Bennée {
196e34c47eaSAlex Bennée return status->flush_inputs_to_zero;
197e34c47eaSAlex Bennée }
198e34c47eaSAlex Bennée
get_default_nan_mode(const float_status * status)199db164982SPhilippe Mathieu-Daudé static inline bool get_default_nan_mode(const float_status *status)
200e34c47eaSAlex Bennée {
201e34c47eaSAlex Bennée return status->default_nan_mode;
202e34c47eaSAlex Bennée }
203e34c47eaSAlex Bennée
get_float_ftz_detection(const float_status * status)20428f13bccSPeter Maydell static inline FloatFTZDetection get_float_ftz_detection(const float_status *status)
20528f13bccSPeter Maydell {
20628f13bccSPeter Maydell return status->ftz_detection;
20728f13bccSPeter Maydell }
20828f13bccSPeter Maydell
209ea9cea93SMarkus Armbruster #endif /* SOFTFLOAT_HELPERS_H */
210