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