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 "modf.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. // double modf(double x, double *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. //
  42. // NO FRACTIONAL PART: HUGE
  43. // If
  44. // for double-extended
  45. // If the true exponent is greater than 63
  46. // 1003e ==> 1003e -ffff = 3f = 63(dec)
  47. // for double
  48. // If the true exponent is greater than 52
  49. // 10033 -ffff = 34 = 52(dec)
  50. // for single
  51. // If the true exponent is greater than 23
  52. // 10016 -ffff = 17 = 23(dec)
  53. // then
  54. // we are already an integer (p9 true)
  55. // NO INTEGER PART: SMALL
  56. // Is f8 exponent less than register bias (that is, is it
  57. // less than 1). If it is, get the right sign of
  58. // zero and store this in iptr.
  59. // CALCULATION: NOT HUGE, NOT SMALL
  60. // To get the integer part
  61. // Take the floating-point input and truncate
  62. // then convert this integer to fp Call it MODF_INTEGER_PART
  63. // Subtract MODF_INTEGER_PART from MODF_NORM_F8 to get fraction part
  64. // Then put fraction part in f8
  65. // put integer part MODF_INTEGER_PART into *iptr
  66. // Registers used
  67. //==============================================================
  68. // predicate registers used:
  69. // p6 - p13
  70. // 0xFFFF 0x10033
  71. // -----------------------+-----------------+-------------
  72. // SMALL | NORMAL | HUGE
  73. // p11 --------------->|<----- p12 ----->| <-------------- p9
  74. // p10 --------------------------------->|
  75. // p13 --------------------------------------------------->|
  76. //
  77. // floating-point registers used:
  78. MODF_NORM_F8 = f9
  79. MODF_FRACTION_PART = f10
  80. MODF_INTEGER_PART = f11
  81. MODF_INT_INTEGER_PART = f12
  82. // general registers used
  83. modf_signexp = r14
  84. modf_GR_10033 = r15
  85. modf_GR_FFFF = r16
  86. modf_17_ones = r17
  87. modf_exp = r18
  88. // r33 = iptr
  89. .align 32
  90. .global modf#
  91. .section .text
  92. .proc modf#
  93. .align 32
  94. // Main path is p9, p11, p8 FALSE and p12 TRUE
  95. // Assume input is normalized and get signexp
  96. // Normalize input just in case
  97. // Form exponent bias
  98. modf:
  99. { .mfi
  100. (p0) getf.exp modf_signexp = f8
  101. (p0) fnorm MODF_NORM_F8 = f8
  102. (p0) addl modf_GR_FFFF = 0xffff, r0
  103. }
  104. // Get integer part of input
  105. // Form exponent mask
  106. { .mfi
  107. nop.m 999
  108. (p0) fcvt.fx.trunc.s1 MODF_INT_INTEGER_PART = f8
  109. (p0) mov modf_17_ones = 0x1ffff ;;
  110. }
  111. // Is x unnorm?
  112. // qnan snan inf norm unorm 0 -+
  113. // 0 0 0 0 1 0 11 = 0x0b UNORM
  114. // Form biased exponent where input only has an integer part
  115. { .mfi
  116. nop.m 999
  117. (p0) fclass.m.unc p8,p0 = f8, 0x0b
  118. (p0) addl modf_GR_10033 = 0x10033, r0 ;;
  119. }
  120. // Mask to get exponent
  121. // Is x nan or inf?
  122. // qnan snan inf norm unorm 0 -+
  123. // 1 1 1 0 0 0 11 = 0xe3 NAN_INF
  124. // Set p13 to indicate calculation path, else p6 if nan or inf
  125. { .mfi
  126. (p0) and modf_exp = modf_17_ones, modf_signexp
  127. (p0) fclass.m.unc p6,p13 = f8, 0xe3
  128. nop.i 999 ;;
  129. }
  130. // If x unorm get signexp from normalized input
  131. // If x unorm get integer part from normalized input
  132. { .mfi
  133. (p8) getf.exp modf_signexp = MODF_NORM_F8
  134. (p8) fcvt.fx.trunc MODF_INT_INTEGER_PART = MODF_NORM_F8
  135. nop.i 999 ;;
  136. }
  137. // If x unorm mask to get exponent
  138. // Is x inf? p6 if inf, p7 if nan
  139. { .mfi
  140. (p8) and modf_exp = modf_17_ones, modf_signexp
  141. (p6) fclass.m.unc p6,p7 = f8, 0x23
  142. nop.i 999 ;;
  143. }
  144. // p11 <== SMALL, no integer part, fraction is everyting
  145. // p9 <== HUGE, no fraction part, integer is everything
  146. // p12 <== NORMAL, fraction part and integer part
  147. { .mii
  148. (p13) cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
  149. nop.i 999
  150. nop.i 999 ;;
  151. }
  152. // For SMALL set fraction to normalized input, integer part to signed 0
  153. { .mfi
  154. (p10) cmp.gt.unc p9,p12 = modf_exp, modf_GR_10033
  155. (p11) fmerge.s MODF_INTEGER_PART = f8,f0
  156. nop.i 999
  157. }
  158. { .mfi
  159. nop.m 999
  160. (p11) fnorm.d f8 = MODF_NORM_F8
  161. nop.i 999 ;;
  162. }
  163. // For HUGE set fraction to signed 0
  164. { .mfi
  165. nop.m 999
  166. (p9) fmerge.s f8 = f8,f0
  167. nop.i 999
  168. }
  169. // For NORMAL float the integer part
  170. { .mfi
  171. nop.m 999
  172. (p12) fcvt.xf MODF_INTEGER_PART = MODF_INT_INTEGER_PART
  173. nop.i 999 ;;
  174. }
  175. // If x inf set integer part to INF, fraction to signed 0
  176. { .mfi
  177. (p6) stfd [r33] = MODF_NORM_F8
  178. (p6) fmerge.s f8 = f8,f0
  179. nop.i 999
  180. }
  181. // For HUGE set integer part to normalized input
  182. { .mfi
  183. nop.m 999
  184. (p9) fnorm.d MODF_INTEGER_PART = MODF_NORM_F8
  185. nop.i 999 ;;
  186. }
  187. // If x nan set integer and fraction parts to NaN (quietized)
  188. { .mfi
  189. (p7) stfd [r33] = MODF_NORM_F8
  190. (p7) fmerge.s f8 = MODF_NORM_F8, MODF_NORM_F8
  191. nop.i 999 ;;
  192. }
  193. // For NORMAL compute fraction part
  194. { .mfi
  195. nop.m 999
  196. (p12) fms.d.s0 f8 = MODF_NORM_F8,f1, MODF_INTEGER_PART
  197. nop.i 999
  198. }
  199. // For NORMAL test if fraction part is zero; if so append correct sign
  200. { .mfi
  201. nop.m 999
  202. (p12) fcmp.eq.unc p12,p0 = MODF_NORM_F8, MODF_INTEGER_PART
  203. nop.i 999 ;;
  204. }
  205. // For NORMAL if fraction part is zero append sign of input
  206. { .mfb
  207. (p13) stfd [r33] = MODF_INTEGER_PART
  208. (p12) fmerge.s f8 = MODF_NORM_F8, f8
  209. (p0) br.ret.sptk b0 ;;
  210. }
  211. .endp modf