Math package for float32 / compex64 types https://godoc.org/pkg/math/
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.

exp_amd64.s 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2014 Xuanyi Chew. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //
  5. // The original code is lifted from the Go standard library which is governed by
  6. // a BSD-style licence which can be found here: https://golang.org/LICENSE
  7. #include "textflag.h"
  8. // The method is based on a paper by Naoki Shibata: "Efficient evaluation
  9. // methods of elementary functions suitable for SIMD computation", Proc.
  10. // of International Supercomputing Conference 2010 (ISC'10), pp. 25 -- 32
  11. // (May 2010). The paper is available at
  12. // http://www.springerlink.com/content/340228x165742104/
  13. //
  14. // The original code and the constants below are from the author's
  15. // implementation available at http://freshmeat.net/projects/sleef.
  16. // The README file says, "The software is in public domain.
  17. // You can use the software without any obligation."
  18. //
  19. // This code is a simplified version of the original.
  20. // The magic numbers for the float32 are lifted from the same project
  21. #define LN2 0.693147182464599609375 // log_e(2)
  22. #define LOG2E 1.44269502162933349609375 // 1/LN2
  23. #define LN2U 0.693145751953125 // upper half LN2
  24. #define LN2L 1.428606765330187045e-06 // lower half LN2
  25. #define T0 1.0
  26. #define T1 0.5
  27. #define T2 0.166665524244308471679688
  28. #define T3 0.0416710823774337768554688
  29. #define T4 0.00836596917361021041870117
  30. #define PosInf 0x7F800000
  31. #define NegInf 0xFF800000
  32. // func Exp(x float32) float32
  33. TEXT ·Exp(SB),NOSPLIT,$0
  34. // test bits for not-finite
  35. MOVL x+0(FP), BX
  36. MOVQ $~(1<<31), AX // sign bit mask
  37. MOVL BX, DX
  38. ANDL AX, DX
  39. MOVL $PosInf, AX
  40. CMPL AX, DX
  41. JLE notFinite
  42. MOVL BX, X0
  43. MOVSS $LOG2E, X1
  44. MULSS X0, X1
  45. CVTSS2SL X1, BX // BX = exponent
  46. CVTSL2SS BX, X1
  47. MOVSS $LN2U, X2
  48. MULSS X1, X2
  49. SUBSS X2, X0
  50. MOVSS $LN2L, X2
  51. MULSS X1, X2
  52. SUBSS X2, X0
  53. // reduce argument
  54. MULSS $0.0625, X0
  55. // Taylor series evaluation
  56. ADDSS $T4, X1
  57. MULSS X0, X1
  58. ADDSS $T3, X1
  59. MULSS X0, X1
  60. ADDSS $T2, X1
  61. MULSS X0, X1
  62. ADDSS $T1, X1
  63. MULSS X0, X1
  64. ADDSS $T0, X1
  65. MULSS X1, X0
  66. MOVSS $2.0, X1
  67. ADDSS X0, X1
  68. MULSS X1, X0
  69. MOVSS $2.0, X1
  70. ADDSS X0, X1
  71. MULSS X1, X0
  72. MOVSS $2.0, X1
  73. ADDSS X0, X1
  74. MULSS X1, X0
  75. MOVSS $2.0, X1
  76. ADDSS X0, X1
  77. MULSS X1, X0
  78. ADDSS $1.0, X0
  79. // return fr * 2**exponent
  80. MOVL $0x7F, AX // bias
  81. ADDL AX, BX
  82. JLE underflow
  83. CMPL BX, $0xFF
  84. JGE overflow
  85. MOVL $23, CX
  86. SHLQ CX, BX
  87. MOVL BX, X1
  88. MULSS X1, X0
  89. MOVSS X0, ret+8(FP)
  90. RET
  91. notFinite:
  92. // test bits for -Inf
  93. MOVL $NegInf, AX
  94. CMPQ AX, BX
  95. JNE notNegInf
  96. // -Inf, return 0
  97. underflow: // return 0
  98. MOVL $0, AX
  99. MOVL AX, ret+8(FP)
  100. RET
  101. overflow: // return +Inf
  102. MOVL $PosInf, BX
  103. notNegInf: // NaN or +Inf, return x
  104. MOVL BX, ret+8(FP)
  105. RET