xref: /qemu/include/fpu/softfloat-helpers.h (revision a828b373bdabc7e53d1e218e3fc76f85b6674688)
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 
51e34c47eaSAlex Bennée #ifndef _SOFTFLOAT_HELPERS_H_
52e34c47eaSAlex Bennée #define _SOFTFLOAT_HELPERS_H_
53e34c47eaSAlex Bennée 
54e34c47eaSAlex Bennée #include "fpu/softfloat-types.h"
55e34c47eaSAlex Bennée 
56*a828b373SRichard Henderson static inline void set_float_detect_tininess(bool val, float_status *status)
57e34c47eaSAlex Bennée {
58*a828b373SRichard Henderson     status->tininess_before_rounding = val;
59e34c47eaSAlex Bennée }
60e34c47eaSAlex Bennée 
61e34c47eaSAlex Bennée static inline void set_float_rounding_mode(int val, float_status *status)
62e34c47eaSAlex Bennée {
63e34c47eaSAlex Bennée     status->float_rounding_mode = val;
64e34c47eaSAlex Bennée }
65e34c47eaSAlex Bennée 
66e34c47eaSAlex Bennée static inline void set_float_exception_flags(int val, float_status *status)
67e34c47eaSAlex Bennée {
68e34c47eaSAlex Bennée     status->float_exception_flags = val;
69e34c47eaSAlex Bennée }
70e34c47eaSAlex Bennée 
71e34c47eaSAlex Bennée static inline void set_floatx80_rounding_precision(int val,
72e34c47eaSAlex Bennée                                                    float_status *status)
73e34c47eaSAlex Bennée {
74e34c47eaSAlex Bennée     status->floatx80_rounding_precision = val;
75e34c47eaSAlex Bennée }
76e34c47eaSAlex Bennée 
77c120391cSRichard Henderson static inline void set_flush_to_zero(bool val, float_status *status)
78e34c47eaSAlex Bennée {
79e34c47eaSAlex Bennée     status->flush_to_zero = val;
80e34c47eaSAlex Bennée }
81e34c47eaSAlex Bennée 
82c120391cSRichard Henderson static inline void set_flush_inputs_to_zero(bool val, float_status *status)
83e34c47eaSAlex Bennée {
84e34c47eaSAlex Bennée     status->flush_inputs_to_zero = val;
85e34c47eaSAlex Bennée }
86e34c47eaSAlex Bennée 
87c120391cSRichard Henderson static inline void set_default_nan_mode(bool val, float_status *status)
88e34c47eaSAlex Bennée {
89e34c47eaSAlex Bennée     status->default_nan_mode = val;
90e34c47eaSAlex Bennée }
91e34c47eaSAlex Bennée 
92c120391cSRichard Henderson static inline void set_snan_bit_is_one(bool val, float_status *status)
93e34c47eaSAlex Bennée {
94e34c47eaSAlex Bennée     status->snan_bit_is_one = val;
95e34c47eaSAlex Bennée }
96e34c47eaSAlex Bennée 
97*a828b373SRichard Henderson static inline bool get_float_detect_tininess(float_status *status)
98e34c47eaSAlex Bennée {
99*a828b373SRichard Henderson     return status->tininess_before_rounding;
100e34c47eaSAlex Bennée }
101e34c47eaSAlex Bennée 
102e34c47eaSAlex Bennée static inline int get_float_rounding_mode(float_status *status)
103e34c47eaSAlex Bennée {
104e34c47eaSAlex Bennée     return status->float_rounding_mode;
105e34c47eaSAlex Bennée }
106e34c47eaSAlex Bennée 
107e34c47eaSAlex Bennée static inline int get_float_exception_flags(float_status *status)
108e34c47eaSAlex Bennée {
109e34c47eaSAlex Bennée     return status->float_exception_flags;
110e34c47eaSAlex Bennée }
111e34c47eaSAlex Bennée 
112e34c47eaSAlex Bennée static inline int get_floatx80_rounding_precision(float_status *status)
113e34c47eaSAlex Bennée {
114e34c47eaSAlex Bennée     return status->floatx80_rounding_precision;
115e34c47eaSAlex Bennée }
116e34c47eaSAlex Bennée 
117c120391cSRichard Henderson static inline bool get_flush_to_zero(float_status *status)
118e34c47eaSAlex Bennée {
119e34c47eaSAlex Bennée     return status->flush_to_zero;
120e34c47eaSAlex Bennée }
121e34c47eaSAlex Bennée 
122c120391cSRichard Henderson static inline bool get_flush_inputs_to_zero(float_status *status)
123e34c47eaSAlex Bennée {
124e34c47eaSAlex Bennée     return status->flush_inputs_to_zero;
125e34c47eaSAlex Bennée }
126e34c47eaSAlex Bennée 
127c120391cSRichard Henderson static inline bool get_default_nan_mode(float_status *status)
128e34c47eaSAlex Bennée {
129e34c47eaSAlex Bennée     return status->default_nan_mode;
130e34c47eaSAlex Bennée }
131e34c47eaSAlex Bennée 
132e34c47eaSAlex Bennée #endif /* _SOFTFLOAT_HELPERS_H_ */
133