Leaked source code of windows server 2003
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.

269 lines
7.4 KiB

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