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.

218 lines
5.9 KiB

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