dfminmax.S 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //===----------------------Hexagon builtin routine ------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #define A r1:0
  9. #define B r3:2
  10. #define ATMP r5:4
  11. #define Q6_ALIAS(TAG) .global __qdsp_##TAG ; .set __qdsp_##TAG, __hexagon_##TAG
  12. #define END(TAG) .size TAG,.-TAG
  13. // Min and Max return A if B is NaN, or B if A is NaN
  14. // Otherwise, they return the smaller or bigger value
  15. //
  16. // If values are equal, we want to favor -0.0 for min and +0.0 for max.
  17. // Compares always return false for NaN
  18. // if (isnan(A)) A = B; if (A > B) A = B will only trigger at most one of those options.
  19. .text
  20. .global __hexagon_mindf3
  21. .global __hexagon_maxdf3
  22. .global fmin
  23. .type fmin,@function
  24. .global fmax
  25. .type fmax,@function
  26. .type __hexagon_mindf3,@function
  27. .type __hexagon_maxdf3,@function
  28. Q6_ALIAS(mindf3)
  29. Q6_ALIAS(maxdf3)
  30. .p2align 5
  31. __hexagon_mindf3:
  32. fmin:
  33. {
  34. p0 = dfclass(A,#0x10) // If A is a number
  35. p1 = dfcmp.gt(A,B) // AND B > A, don't swap
  36. ATMP = A
  37. }
  38. {
  39. if (p0) A = B // if A is NaN use B
  40. if (p1) A = B // gt is always false if either is NaN
  41. p2 = dfcmp.eq(A,B) // if A == B
  42. if (!p2.new) jumpr:t r31
  43. }
  44. // A == B, return A|B to select -0.0 over 0.0
  45. {
  46. A = or(ATMP,B)
  47. jumpr r31
  48. }
  49. END(__hexagon_mindf3)
  50. .falign
  51. __hexagon_maxdf3:
  52. fmax:
  53. {
  54. p0 = dfclass(A,#0x10)
  55. p1 = dfcmp.gt(B,A)
  56. ATMP = A
  57. }
  58. {
  59. if (p0) A = B
  60. if (p1) A = B
  61. p2 = dfcmp.eq(A,B)
  62. if (!p2.new) jumpr:t r31
  63. }
  64. // A == B, return A&B to select 0.0 over -0.0
  65. {
  66. A = and(ATMP,B)
  67. jumpr r31
  68. }
  69. END(__hexagon_maxdf3)