Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
6.6 KiB

  1. .file "modff.s"
  2. // Copyright (c) 2000, Intel Corporation
  3. // All rights reserved.
  4. //
  5. // Contributed 2/2/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
  6. // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
  7. //
  8. // WARRANTY DISCLAIMER
  9. //
  10. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  11. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  12. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  13. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
  14. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  15. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17. // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  18. // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
  19. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. //
  22. // Intel Corporation is the author of this code, and requests that all
  23. // problem reports or change requests be submitted to it directly at
  24. // http://developer.intel.com/opensource.
  25. //
  26. // History
  27. //==============================================================
  28. // 2/02/00: Initial version
  29. // 4/04/00: Improved speed, corrected result for NaN input
  30. //
  31. // API
  32. //==============================================================
  33. // float modff(float x, float *iptr)
  34. // break a floating point x number into fraction and an exponent
  35. //
  36. // input floating point f8, address in r33
  37. // output floating point f8 (x fraction), and *iptr (x integral part)
  38. //
  39. // OVERVIEW
  40. //==============================================================
  41. // NO FRACTIONAL PART: HUGE
  42. // If
  43. // for double-extended
  44. // If the true exponent is greater than 63
  45. // 1003e ==> 1003e -ffff = 3f = 63(dec)
  46. // for double
  47. // If the true exponent is greater than 52
  48. // 10033 -ffff = 34 = 52(dec)
  49. // for single
  50. // If the true exponent is greater than 23
  51. // 10016 -ffff = 17 = 23(dec)
  52. // then
  53. // we are already an integer (p9 true)
  54. // NO INTEGER PART: SMALL
  55. // Is f8 exponent less than register bias (that is, is it
  56. // less than 1). If it is, get the right sign of
  57. // zero and store this in iptr.
  58. // CALCULATION: NOT HUGE, NOT SMALL
  59. // To get the integer part
  60. // Take the floating-point input and truncate
  61. // then convert this integer to fp Call it MODF_INTEGER_PART
  62. // Subtract MODF_INTEGER_PART from MODF_NORM_F8 to get fraction part
  63. // Then put fraction part in f8
  64. // put integer part MODF_INTEGER_PART into *iptr
  65. // Registers used
  66. //==============================================================
  67. // predicate registers used:
  68. // p6 - p13
  69. // 0xFFFF 0x10016
  70. // -----------------------+-----------------+-------------
  71. // SMALL | NORMAL | HUGE
  72. // p11 --------------->|<----- p12 ----->| <-------------- p9
  73. // p10 --------------------------------->|
  74. // p13 --------------------------------------------------->|
  75. //
  76. // floating-point registers used:
  77. MODF_NORM_F8 = f9
  78. MODF_FRACTION_PART = f10
  79. MODF_INTEGER_PART = f11
  80. MODF_INT_INTEGER_PART = f12
  81. // general registers used
  82. modf_signexp = r14
  83. modf_GR_10016 = r15
  84. modf_GR_FFFF = r16
  85. modf_17_ones = r17
  86. modf_exp = r18
  87. // r33 = iptr
  88. .align 32
  89. .global modff#
  90. .section .text
  91. .proc modff#
  92. .align 32
  93. // Main path is p9, p11, p8 FALSE and p12 TRUE
  94. // Assume input is normalized and get signexp
  95. // Normalize input just in case
  96. // Form exponent bias
  97. modff:
  98. { .mfi
  99. (p0) getf.exp modf_signexp = f8
  100. (p0) fnorm MODF_NORM_F8 = f8
  101. (p0) addl modf_GR_FFFF = 0xffff, r0
  102. }
  103. // Get integer part of input
  104. // Form exponent mask
  105. { .mfi
  106. nop.m 999
  107. (p0) fcvt.fx.trunc.s1 MODF_INT_INTEGER_PART = f8
  108. (p0) mov modf_17_ones = 0x1ffff ;;
  109. }
  110. // Is x unnorm?
  111. // qnan snan inf norm unorm 0 -+
  112. // 0 0 0 0 1 0 11 = 0x0b UNORM
  113. // Form biased exponent where input only has an integer part
  114. { .mfi
  115. nop.m 999
  116. (p0) fclass.m.unc p8,p0 = f8, 0x0b
  117. (p0) addl modf_GR_10016 = 0x10016, r0 ;;
  118. }
  119. // Mask to get exponent
  120. // Is x nan or inf?
  121. // qnan snan inf norm unorm 0 -+
  122. // 1 1 1 0 0 0 11 = 0xe3 NAN_INF
  123. // Set p13 to indicate calculation path, else p6 if nan or inf
  124. { .mfi
  125. (p0) and modf_exp = modf_17_ones, modf_signexp
  126. (p0) fclass.m.unc p6,p13 = f8, 0xe3
  127. nop.i 999 ;;
  128. }
  129. // If x unorm get signexp from normalized input
  130. // If x unorm get integer part from normalized input
  131. { .mfi
  132. (p8) getf.exp modf_signexp = MODF_NORM_F8
  133. (p8) fcvt.fx.trunc MODF_INT_INTEGER_PART = MODF_NORM_F8
  134. nop.i 999 ;;
  135. }
  136. // If x unorm mask to get exponent
  137. // Is x inf? p6 if inf, p7 if nan
  138. { .mfi
  139. (p8) and modf_exp = modf_17_ones, modf_signexp
  140. (p6) fclass.m.unc p6,p7 = f8, 0x23
  141. nop.i 999 ;;
  142. }
  143. // p11 <== SMALL, no integer part, fraction is everyting
  144. // p9 <== HUGE, no fraction part, integer is everything
  145. // p12 <== NORMAL, fraction part and integer part
  146. { .mii
  147. (p13) cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
  148. nop.i 999
  149. nop.i 999 ;;
  150. }
  151. // For SMALL set fraction to normalized input, integer part to signed 0
  152. { .mfi
  153. (p10) cmp.gt.unc p9,p12 = modf_exp, modf_GR_10016
  154. (p11) fmerge.s MODF_INTEGER_PART = f8,f0
  155. nop.i 999
  156. }
  157. { .mfi
  158. nop.m 999
  159. (p11) fnorm.s f8 = MODF_NORM_F8
  160. nop.i 999 ;;
  161. }
  162. // For HUGE set fraction to signed 0
  163. { .mfi
  164. nop.m 999
  165. (p9) fmerge.s f8 = f8,f0
  166. nop.i 999
  167. }
  168. // For NORMAL float the integer part
  169. { .mfi
  170. nop.m 999
  171. (p12) fcvt.xf MODF_INTEGER_PART = MODF_INT_INTEGER_PART
  172. nop.i 999 ;;
  173. }
  174. // If x inf set integer part to INF, fraction to signed 0
  175. { .mfi
  176. (p6) stfs [r33] = MODF_NORM_F8
  177. (p6) fmerge.s f8 = f8,f0
  178. nop.i 999
  179. }
  180. // For HUGE set integer part to normalized input
  181. { .mfi
  182. nop.m 999
  183. (p9) fnorm.s MODF_INTEGER_PART = MODF_NORM_F8
  184. nop.i 999 ;;
  185. }
  186. // If x nan set integer and fraction parts to NaN (quietized)
  187. { .mfi
  188. (p7) stfs [r33] = MODF_NORM_F8
  189. (p7) fmerge.s f8 = MODF_NORM_F8, MODF_NORM_F8
  190. nop.i 999 ;;
  191. }
  192. // For NORMAL compute fraction part
  193. { .mfi
  194. nop.m 999
  195. (p12) fms.s.s0 f8 = MODF_NORM_F8,f1, MODF_INTEGER_PART
  196. nop.i 999
  197. }
  198. // For NORMAL test if fraction part is zero; if so append correct sign
  199. { .mfi
  200. nop.m 999
  201. (p12) fcmp.eq.unc p12,p0 = MODF_NORM_F8, MODF_INTEGER_PART
  202. nop.i 999 ;;
  203. }
  204. // For NORMAL if fraction part is zero append sign of input
  205. { .mfb
  206. (p13) stfs [r33] = MODF_INTEGER_PART
  207. (p12) fmerge.s f8 = MODF_NORM_F8, f8
  208. (p0) br.ret.sptk b0 ;;
  209. }
  210. .endp modff