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.

384 lines
8.2 KiB

  1. .file "hypotf.asm"
  2. // Copyright (c) 2000, Intel Corporation
  3. // All rights reserved.
  4. //
  5. // Contributed 2/2/2000 by John Harrison, Cristina Iordache, Ted Kubaska,
  6. // Bob Norin, Shane Story, and Ping Tak Peter Tang of the
  7. // Computational Software Lab, Intel Corporation.
  8. //
  9. // WARRANTY DISCLAIMER
  10. //
  11. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  12. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  13. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  14. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
  15. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18. // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  19. // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
  20. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. //
  23. // Intel Corporation is the author of this code, and requests that all
  24. // problem reports or change requests be submitted to it directly at
  25. // http://developer.intel.com/opensource.
  26. //
  27. //*********************************************************************
  28. //
  29. // History:
  30. // 2/02/00 hand-optimized
  31. // 4/04/00 Unwind support added
  32. // 6/26/00 new version
  33. // 8/15/00 Bundle added after call to __libm_error_support to properly
  34. // set [the previously overwritten] GR_Parameter_RESULT.
  35. //
  36. //*********************************************************************
  37. // ___________
  38. // Function: hypotf(x,y) = |(x^2 + y^2) = for single precision values
  39. // x and y
  40. // Also provides cabsf functionality.
  41. //
  42. //*********************************************************************
  43. //
  44. // Resources Used:
  45. //
  46. // Floating-Point Registers: f8 (Input and Return Value)
  47. // f9 (Input)
  48. // f6 -f15
  49. //
  50. // General Purpose Registers:
  51. // r2-r3 (Scratch)
  52. // r32-r36 (Locals)
  53. // r37-r40 (Used to pass arguments to error handling routine)
  54. //
  55. // Predicate Registers: p6 - p10
  56. //
  57. //*********************************************************************
  58. //
  59. // IEEE Special Conditions:
  60. //
  61. // All faults and exceptions should be raised correctly.
  62. // Overflow can occur.
  63. // hypotf(Infinity and anything) = +Infinity
  64. // hypotf(QNaN and anything) = QNaN
  65. // hypotf(SNaN and anything ) = QNaN
  66. //
  67. //*********************************************************************
  68. //
  69. // Implementation:
  70. // x2 = x * x in double-extended
  71. // y2 = y * y in double-extended
  72. // temp = x2 + y2 in double-extended
  73. // sqrt(temp) rounded to single precision
  74. //
  75. //*********************************************************************
  76. GR_SAVE_PFS = r33
  77. GR_SAVE_B0 = r34
  78. GR_SAVE_GP = r35
  79. GR_Parameter_X = r36
  80. GR_Parameter_Y = r37
  81. GR_Parameter_RESULT = r38
  82. GR_Parameter_TAG = r39
  83. FR_X = f14
  84. FR_Y = f15
  85. FR_RESULT = f8
  86. .section .text
  87. .proc _cabsf#
  88. .global _cabsf#
  89. _cabsf:
  90. .endp _cabsf
  91. .proc _hypotf#
  92. .global _hypotf#
  93. .align 64
  94. _hypotf:
  95. {.mfi
  96. alloc r32= ar.pfs,0,4,4,0
  97. // Compute x*x
  98. fma.s1 f10=f8,f8,f0
  99. // r2=bias-1
  100. mov r2=0xfffe
  101. }
  102. {.mfi
  103. nop.m 0
  104. // y*y
  105. fma.s1 f11=f9,f9,f0
  106. nop.i 0;;
  107. }
  108. { .mfi
  109. nop.m 0
  110. // Check if x is an Inf - if so return Inf even
  111. // if y is a NaN (C9X)
  112. fclass.m.unc p7, p6 = f8, 0x023
  113. nop.i 0
  114. }
  115. {.mfi
  116. nop.m 0
  117. // if possible overflow, copy f8 to f14
  118. // set Denormal, if necessary
  119. // (p8)
  120. fma.s.s0 f14=f8,f1,f0
  121. nop.i 0;;
  122. }
  123. { .mfi
  124. nop.m 0
  125. // Check if y is an Inf - if so return Inf even
  126. // if x is a NaN (C9X)
  127. fclass.m.unc p8, p9 = f9, 0x023
  128. nop.i 0
  129. }
  130. { .mfi
  131. nop.m 0
  132. // For x=inf, multiply y by 1 to raise invalid on y an SNaN
  133. // (p7) fma.s0 f9=f9,f1,f0
  134. // copy f9 to f15; set Denormal, if necessary
  135. fma.s.s0 f15=f9,f1,f0
  136. nop.i 0;;
  137. }
  138. {.mfi
  139. nop.m 0
  140. // is y Zero ?
  141. (p6) fclass.m p6,p0=f9,0x7
  142. nop.i 0;;
  143. }
  144. {.mfi
  145. nop.m 0
  146. // is x Zero ?
  147. (p9) fclass.m p9,p0=f8,0x7
  148. nop.i 0;;
  149. }
  150. {.mfi
  151. // f7=0.5
  152. setf.exp f7=r2
  153. // a=x2+y2
  154. fma.s1 f12=f10,f1,f11
  155. nop.i 0;;
  156. }
  157. {.mfi
  158. nop.m 0
  159. // x not NaN ?
  160. (p6) fclass.m p7,p0=f8,0x3f
  161. nop.i 0
  162. }
  163. {.mfi
  164. // 2*emax-2
  165. mov r2=0x100fb
  166. // f6=2
  167. fma.s1 f6=f1,f1,f1
  168. nop.i 0;;
  169. }
  170. {.mfi
  171. nop.m 0
  172. // y not NaN ?
  173. (p9) fclass.m p8,p0=f9,0x3f
  174. nop.i 0;;
  175. }
  176. {.mfb
  177. nop.m 0
  178. // if f8=Infinity or f9=Zero, return |f8|
  179. (p7) fmerge.s f8=f0,f14
  180. (p7) br.ret.spnt b0
  181. }
  182. {.mfb
  183. nop.m 0
  184. // if f9=Infinity or f8=Zero, return |f9|
  185. (p8) fmerge.s f8=f0,f15
  186. (p8) br.ret.spnt b0;;
  187. }
  188. { .mfi
  189. nop.m 0
  190. // Identify Natvals, Infs, NaNs, and Zeros
  191. // and return result
  192. fclass.m.unc p7, p0 = f12, 0x1E7
  193. nop.i 0
  194. }
  195. {.mfi
  196. nop.m 0
  197. // z0=frsqrta(a)
  198. frsqrta.s1 f8,p6=f12
  199. nop.i 0;;
  200. }
  201. {.mfb
  202. // get exponent of x^2+y^2
  203. getf.exp r3=f12
  204. // if special case, set f8
  205. (p7) mov f8=f12
  206. (p7) br.ret.spnt b0;;
  207. }
  208. {.mfi
  209. nop.m 0
  210. // S0=a*z0
  211. (p6) fma.s1 f12=f12,f8,f0
  212. nop.i 0
  213. }
  214. {.mfi
  215. nop.m 0
  216. // H0=0.5*z0
  217. (p6) fma.s1 f10=f8,f7,f0
  218. nop.i 0;;
  219. }
  220. {.mfi
  221. nop.m 0
  222. // f6=5/2
  223. fma.s1 f6=f7,f1,f6
  224. nop.i 0
  225. }
  226. {.mfi
  227. nop.m 0
  228. // f11=3/2
  229. fma.s1 f11=f7,f1,f1
  230. nop.i 0;;
  231. }
  232. {.mfi
  233. nop.m 0
  234. // d=0.5-S0*H0
  235. (p6) fnma.s1 f7=f12,f10,f7
  236. nop.i 0;;
  237. }
  238. {.mfi
  239. nop.m 0
  240. // P01=d+1
  241. (p6) fma.s1 f10=f1,f7,f1
  242. nop.i 0
  243. }
  244. {.mfi
  245. nop.m 0
  246. // P23=5/2*d+3/2
  247. (p6) fma.s1 f11=f6,f7,f11
  248. nop.i 0;;
  249. }
  250. {.mfi
  251. nop.m 0
  252. // d2=d*d
  253. (p6) fma.s1 f7=f7,f7,f0
  254. nop.i 0;;
  255. }
  256. {.mfi
  257. // Is x^2 + y^2 well less than the overflow
  258. // threshold?
  259. (p6) cmp.lt.unc p7, p8 = r3,r2
  260. // P=P01+d2*P23
  261. (p6) fma.s1 f10=f7,f11,f10
  262. nop.i 0;;
  263. }
  264. {.mfb
  265. nop.m 0
  266. // S=P*S0
  267. fma.s.s0 f8=f10,f12,f0
  268. // No overflow in this case
  269. (p7) br.ret.sptk b0;;
  270. }
  271. { .mfi
  272. nop.m 0
  273. (p8) fsetc.s2 0x7F,0x42
  274. // Possible overflow path, must detect by
  275. // Setting widest range exponent with prevailing
  276. // rounding mode.
  277. nop.i 0 ;;
  278. }
  279. { .mfi
  280. // bias+0x400 (bias+EMAX+1)
  281. (p8) mov r2=0x1007f
  282. // S=P*S0
  283. (p8) fma.s.s2 f12=f10,f12,f0
  284. nop.i 0 ;;
  285. }
  286. { .mfi
  287. (p8) setf.exp f11 = r2
  288. (p8) fsetc.s2 0x7F,0x40
  289. // Restore Original Mode in S2
  290. nop.i 0 ;;
  291. }
  292. { .mfi
  293. nop.m 0
  294. (p8) fcmp.lt.unc.s1 p9, p10 = f12, f11
  295. nop.i 0 ;;
  296. }
  297. { .mib
  298. nop.m 0
  299. mov GR_Parameter_TAG = 47
  300. // No overflow
  301. (p9) br.ret.sptk b0;;
  302. }
  303. .endp
  304. .proc __libm_error_region
  305. __libm_error_region:
  306. .prologue
  307. { .mii
  308. add GR_Parameter_Y=-32,sp // Parameter 2 value
  309. (p0) mov GR_Parameter_TAG = 47
  310. .save ar.pfs,GR_SAVE_PFS
  311. mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
  312. }
  313. { .mfi
  314. .fframe 64
  315. add sp=-64,sp // Create new stack
  316. nop.f 0
  317. mov GR_SAVE_GP=gp // Save gp
  318. };;
  319. { .mmi
  320. stfs [GR_Parameter_Y] = FR_Y,16 // Store Parameter 2 on stack
  321. add GR_Parameter_X = 16,sp // Parameter 1 address
  322. .save b0, GR_SAVE_B0
  323. mov GR_SAVE_B0=b0 // Save b0
  324. };;
  325. .body
  326. { .mib
  327. stfs [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
  328. add GR_Parameter_RESULT = 0,GR_Parameter_Y
  329. nop.b 0 // Parameter 3 address
  330. }
  331. { .mib
  332. stfs [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
  333. add GR_Parameter_Y = -16,GR_Parameter_Y
  334. br.call.sptk b0=__libm_error_support# // Call error handling function
  335. };;
  336. { .mmi
  337. nop.m 0
  338. nop.m 0
  339. add GR_Parameter_RESULT = 48,sp
  340. };;
  341. { .mmi
  342. ldfs f8 = [GR_Parameter_RESULT] // Get return result off stack
  343. .restore
  344. add sp = 64,sp // Restore stack pointer
  345. mov b0 = GR_SAVE_B0 // Restore return address
  346. };;
  347. { .mib
  348. mov gp = GR_SAVE_GP // Restore gp
  349. mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
  350. br.ret.sptk b0 // Return
  351. };;
  352. .endp __libm_error_region
  353. .type __libm_error_support#,@function
  354. .global __libm_error_support#