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.

221 lines
6.0 KiB

  1. .file "floor.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. .align 32
  27. .global floor#
  28. .section .text
  29. .proc floor#
  30. .align 32
  31. // History
  32. //==============================================================
  33. // 2/02/00: Initial version
  34. // 3/22/00: Updated to improve performance
  35. // 6/13/00: Improved speed, fixed setting of inexact flag
  36. // 6/27/00: Eliminated incorrect invalid flag setting
  37. // 2/07/01: Corrected sign of zero result in round to -inf mode
  38. // API
  39. //==============================================================
  40. // double floor(double x)
  41. // general input registers:
  42. floor_GR_FFFF = r14
  43. floor_GR_signexp = r15
  44. floor_GR_exponent = r16
  45. floor_GR_expmask = r17
  46. floor_GR_bigexp = r18
  47. // predicate registers used:
  48. // p6 ==> Input is NaN, infinity, zero
  49. // p7 ==> Input is denormal
  50. // p8 ==> Input is <0
  51. // p9 ==> Input is >=0
  52. // p10 ==> Input is already an integer (bigger than largest integer)
  53. // p11 ==> Input is not a large integer
  54. // p12 ==> Input is a smaller integer
  55. // p13 ==> Input is not an even integer, so inexact must be set
  56. // floating-point registers used:
  57. FLOOR_NORM_f8 = f9
  58. FLOOR_FFFF = f10
  59. FLOOR_INEXACT = f11
  60. FLOOR_FLOAT_INT_f8 = f12
  61. FLOOR_INT_f8 = f13
  62. FLOOR_adj = f14
  63. // Overview of operation
  64. //==============================================================
  65. // double floor(double x)
  66. // Return an integer value (represented as a double) that is the largest
  67. // value not greater than x
  68. // This is x rounded toward -infinity to an integral value.
  69. // Inexact is set if x != floor(x)
  70. // **************************************************************************
  71. // Set denormal flag for denormal input and
  72. // and take denormal fault if necessary.
  73. // Is the input an integer value already?
  74. // double_extended
  75. // if the exponent is > 1003e => 3F(true) = 63(decimal)
  76. // we have a significand of 64 bits 1.63-bits.
  77. // If we multiply by 2^63, we no longer have a fractional part
  78. // So input is an integer value already.
  79. // double
  80. // if the exponent is >= 10033 => 34(true) = 52(decimal)
  81. // 34 + 3ff = 433
  82. // we have a significand of 53 bits 1.52-bits. (implicit 1)
  83. // If we multiply by 2^52, we no longer have a fractional part
  84. // So input is an integer value already.
  85. // single
  86. // if the exponent is > 10016 => 17(true) = 23(decimal)
  87. // we have a significand of 24 bits 1.23-bits. (implicit 1)
  88. // If we multiply by 2^23, we no longer have a fractional part
  89. // So input is an integer value already.
  90. // If x is NAN, ZERO, or INFINITY, then return
  91. // qnan snan inf norm unorm 0 -+
  92. // 1 1 1 0 0 1 11 0xe7
  93. floor:
  94. { .mfi
  95. getf.exp floor_GR_signexp = f8
  96. fcvt.fx.trunc.s1 FLOOR_INT_f8 = f8
  97. addl floor_GR_bigexp = 0x10033, r0
  98. }
  99. { .mfi
  100. addl floor_GR_FFFF = -1,r0
  101. fcmp.lt.s1 p8,p9 = f8,f0
  102. mov floor_GR_expmask = 0x1FFFF ;;
  103. }
  104. // p7 ==> denorm
  105. { .mfi
  106. setf.sig FLOOR_FFFF = floor_GR_FFFF
  107. fclass.m p7,p0 = f8, 0x0b
  108. nop.i 999
  109. }
  110. { .mfi
  111. nop.m 999
  112. fnorm.s1 FLOOR_NORM_f8 = f8
  113. nop.i 999 ;;
  114. }
  115. // p6 ==> NAN, INF, ZERO
  116. { .mfb
  117. nop.m 999
  118. fclass.m p6,p10 = f8, 0xe7
  119. (p7) br.cond.spnt FLOOR_DENORM ;;
  120. }
  121. .pred.rel "mutex",p8,p9
  122. FLOOR_COMMON:
  123. // Set adjustment to subtract from trunc(x) for result
  124. // If x<0, adjustment is -1.0
  125. // If x>=0, adjustment is 0.0
  126. { .mfi
  127. and floor_GR_exponent = floor_GR_signexp, floor_GR_expmask
  128. (p8) fnma.s1 FLOOR_adj = f1,f1,f0
  129. nop.i 999
  130. }
  131. { .mfi
  132. nop.m 999
  133. (p9) fadd.s1 FLOOR_adj = f0,f0
  134. nop.i 999 ;;
  135. }
  136. { .mfi
  137. nop.m 999
  138. fcmp.eq.s0 p12,p0 = f8,f0 // Dummy op to set denormal and invalid flag
  139. nop.i 999
  140. }
  141. { .mfi
  142. (p10) cmp.ge.unc p10,p11 = floor_GR_exponent, floor_GR_bigexp
  143. (p6) fnorm.d f8 = f8
  144. nop.i 999 ;;
  145. }
  146. { .mfi
  147. nop.m 999
  148. (p11) fcvt.xf FLOOR_FLOAT_INT_f8 = FLOOR_INT_f8
  149. nop.i 999 ;;
  150. }
  151. { .mfi
  152. nop.m 999
  153. (p10) fnorm.d f8 = FLOOR_NORM_f8
  154. nop.i 999 ;;
  155. }
  156. { .mfi
  157. nop.m 999
  158. (p11) fadd.d f8 = FLOOR_FLOAT_INT_f8,FLOOR_adj
  159. nop.i 999 ;;
  160. }
  161. { .mfi
  162. nop.m 999
  163. (p11) fcmp.eq.unc.s1 p12,p13 = FLOOR_FLOAT_INT_f8, FLOOR_NORM_f8
  164. nop.i 999 ;;
  165. }
  166. // Set inexact if result not equal to input
  167. { .mfi
  168. nop.m 999
  169. (p13) fmpy.s0 FLOOR_INEXACT = FLOOR_FFFF,FLOOR_FFFF
  170. nop.i 999
  171. }
  172. // Set result to input if integer
  173. { .mfb
  174. nop.m 999
  175. (p12) fnorm.d f8 = FLOOR_NORM_f8
  176. br.ret.sptk b0 ;;
  177. }
  178. // Here if input denorm
  179. FLOOR_DENORM:
  180. { .mfb
  181. getf.exp floor_GR_signexp = FLOOR_NORM_f8
  182. fcvt.fx.trunc.s1 FLOOR_INT_f8 = FLOOR_NORM_f8
  183. br.cond.sptk FLOOR_COMMON ;;
  184. }
  185. .endp floor