softfloat-helpers.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. This C header file is part of the SoftFloat IEC/IEEE Floating-point
  24. Arithmetic Package, Release 2a.
  25. Written by John R. Hauser. This work was made possible in part by the
  26. International Computer Science Institute, located at Suite 600, 1947 Center
  27. Street, Berkeley, California 94704. Funding was partially provided by the
  28. National Science Foundation under grant MIP-9311980. The original version
  29. of this code was written as part of a project to build a fixed-point vector
  30. processor in collaboration with the University of California at Berkeley,
  31. overseen by Profs. Nelson Morgan and John Wawrzynek. More information
  32. is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/
  33. arithmetic/SoftFloat.html'.
  34. THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort
  35. has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
  36. TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO
  37. PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
  38. AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
  39. Derivative works are acceptable, even for commercial purposes, so long as
  40. (1) they include prominent notice that the work is derivative, and (2) they
  41. include prominent notice akin to these four paragraphs for those parts of
  42. this code that are retained.
  43. ===============================================================================
  44. */
  45. #ifndef SOFTFLOAT_HELPERS_H
  46. #define SOFTFLOAT_HELPERS_H
  47. #include "fpu/softfloat-types.h"
  48. static inline void set_float_detect_tininess(bool val, float_status *status)
  49. {
  50. status->tininess_before_rounding = val;
  51. }
  52. static inline void set_float_rounding_mode(FloatRoundMode val,
  53. float_status *status)
  54. {
  55. status->float_rounding_mode = val;
  56. }
  57. static inline void set_float_exception_flags(int val, float_status *status)
  58. {
  59. status->float_exception_flags = val;
  60. }
  61. static inline void set_floatx80_rounding_precision(FloatX80RoundPrec val,
  62. float_status *status)
  63. {
  64. status->floatx80_rounding_precision = val;
  65. }
  66. static inline void set_floatx80_behaviour(FloatX80Behaviour b,
  67. float_status *status)
  68. {
  69. status->floatx80_behaviour = b;
  70. }
  71. static inline void set_float_2nan_prop_rule(Float2NaNPropRule rule,
  72. float_status *status)
  73. {
  74. status->float_2nan_prop_rule = rule;
  75. }
  76. static inline void set_float_3nan_prop_rule(Float3NaNPropRule rule,
  77. float_status *status)
  78. {
  79. status->float_3nan_prop_rule = rule;
  80. }
  81. static inline void set_float_infzeronan_rule(FloatInfZeroNaNRule rule,
  82. float_status *status)
  83. {
  84. status->float_infzeronan_rule = rule;
  85. }
  86. static inline void set_float_default_nan_pattern(uint8_t dnan_pattern,
  87. float_status *status)
  88. {
  89. status->default_nan_pattern = dnan_pattern;
  90. }
  91. static inline void set_flush_to_zero(bool val, float_status *status)
  92. {
  93. status->flush_to_zero = val;
  94. }
  95. static inline void set_flush_inputs_to_zero(bool val, float_status *status)
  96. {
  97. status->flush_inputs_to_zero = val;
  98. }
  99. static inline void set_float_ftz_detection(FloatFTZDetection d,
  100. float_status *status)
  101. {
  102. status->ftz_detection = d;
  103. }
  104. static inline void set_default_nan_mode(bool val, float_status *status)
  105. {
  106. status->default_nan_mode = val;
  107. }
  108. static inline void set_snan_bit_is_one(bool val, float_status *status)
  109. {
  110. status->snan_bit_is_one = val;
  111. }
  112. static inline void set_no_signaling_nans(bool val, float_status *status)
  113. {
  114. status->no_signaling_nans = val;
  115. }
  116. static inline bool get_float_detect_tininess(const float_status *status)
  117. {
  118. return status->tininess_before_rounding;
  119. }
  120. static inline FloatRoundMode get_float_rounding_mode(const float_status *status)
  121. {
  122. return status->float_rounding_mode;
  123. }
  124. static inline int get_float_exception_flags(const float_status *status)
  125. {
  126. return status->float_exception_flags;
  127. }
  128. static inline FloatX80RoundPrec
  129. get_floatx80_rounding_precision(const float_status *status)
  130. {
  131. return status->floatx80_rounding_precision;
  132. }
  133. static inline FloatX80Behaviour
  134. get_floatx80_behaviour(const float_status *status)
  135. {
  136. return status->floatx80_behaviour;
  137. }
  138. static inline Float2NaNPropRule
  139. get_float_2nan_prop_rule(const float_status *status)
  140. {
  141. return status->float_2nan_prop_rule;
  142. }
  143. static inline Float3NaNPropRule
  144. get_float_3nan_prop_rule(const float_status *status)
  145. {
  146. return status->float_3nan_prop_rule;
  147. }
  148. static inline FloatInfZeroNaNRule
  149. get_float_infzeronan_rule(const float_status *status)
  150. {
  151. return status->float_infzeronan_rule;
  152. }
  153. static inline uint8_t get_float_default_nan_pattern(const float_status *status)
  154. {
  155. return status->default_nan_pattern;
  156. }
  157. static inline bool get_flush_to_zero(const float_status *status)
  158. {
  159. return status->flush_to_zero;
  160. }
  161. static inline bool get_flush_inputs_to_zero(const float_status *status)
  162. {
  163. return status->flush_inputs_to_zero;
  164. }
  165. static inline bool get_default_nan_mode(const float_status *status)
  166. {
  167. return status->default_nan_mode;
  168. }
  169. static inline FloatFTZDetection get_float_ftz_detection(const float_status *status)
  170. {
  171. return status->ftz_detection;
  172. }
  173. #endif /* SOFTFLOAT_HELPERS_H */