f2c_specifics.F90 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. ! Copyright (C) 2002-2015 Free Software Foundation, Inc.
  2. ! Contributed by Tobias Schl"uter
  3. !
  4. !This file is part of the GNU Fortran 95 runtime library (libgfortran).
  5. !
  6. !GNU libgfortran is free software; you can redistribute it and/or
  7. !modify it under the terms of the GNU General Public
  8. !License as published by the Free Software Foundation; either
  9. !version 3 of the License, or (at your option) any later version.
  10. !
  11. !GNU libgfortran is distributed in the hope that it will be useful,
  12. !but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. !GNU General Public License for more details.
  15. !
  16. !Under Section 7 of GPL version 3, you are granted additional
  17. !permissions described in the GCC Runtime Library Exception, version
  18. !3.1, as published by the Free Software Foundation.
  19. !
  20. !You should have received a copy of the GNU General Public License and
  21. !a copy of the GCC Runtime Library Exception along with this program;
  22. !see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  23. !<http://www.gnu.org/licenses/>.
  24. ! Specifics for the intrinsics whose calling conventions change if
  25. ! -ff2c is used.
  26. !
  27. ! There are two annoyances WRT the preprocessor:
  28. ! - we're using -traditional-cpp, so we can't use the ## operator.
  29. ! - macros expand to a single line, and Fortran lines can't be wider
  30. ! than 132 characters, therefore we use two macros to split the lines
  31. !
  32. ! The cases we need to implement are functions returning default REAL
  33. ! or COMPLEX. The former need to return DOUBLE PRECISION instead of REAL,
  34. ! the latter become subroutines returning via a hidden first argument.
  35. ! one argument functions
  36. #define REAL_HEAD(NAME) \
  37. elemental function _gfortran_f2c_specific__/**/NAME/**/_r4 (parm) result(res);
  38. #define REAL_BODY(NAME) \
  39. REAL, intent (in) :: parm; \
  40. DOUBLE PRECISION :: res; \
  41. res = NAME (parm); \
  42. end function
  43. #define COMPLEX_HEAD(NAME) \
  44. subroutine _gfortran_f2c_specific__/**/NAME/**/_c4 (res, parm);
  45. #define COMPLEX_BODY(NAME) \
  46. COMPLEX, intent (in) :: parm; \
  47. COMPLEX, intent (out) :: res; \
  48. res = NAME (parm); \
  49. end subroutine
  50. #define DCOMPLEX_HEAD(NAME) \
  51. subroutine _gfortran_f2c_specific__/**/NAME/**/_c8 (res, parm);
  52. #define DCOMPLEX_BODY(NAME) \
  53. DOUBLE COMPLEX, intent (in) :: parm; \
  54. DOUBLE COMPLEX, intent (out) :: res; \
  55. res = NAME (parm); \
  56. end subroutine
  57. REAL_HEAD(abs)
  58. REAL_BODY(abs)
  59. ! abs is special in that the result is real
  60. elemental function _gfortran_f2c_specific__abs_c4 (parm) result (res)
  61. COMPLEX, intent(in) :: parm
  62. DOUBLE PRECISION :: res
  63. res = abs(parm)
  64. end function
  65. ! aimag is special in that the result is real
  66. elemental function _gfortran_f2c_specific__aimag_c4 (parm)
  67. complex(kind=4), intent(in) :: parm
  68. double precision :: _gfortran_f2c_specific__aimag_c4
  69. _gfortran_f2c_specific__aimag_c4 = aimag(parm)
  70. end function
  71. elemental function _gfortran_f2c_specific__aimag_c8 (parm)
  72. complex(kind=8), intent(in) :: parm
  73. double precision :: _gfortran_f2c_specific__aimag_c8
  74. _gfortran_f2c_specific__aimag_c8 = aimag(parm)
  75. end function
  76. REAL_HEAD(exp)
  77. REAL_BODY(exp)
  78. COMPLEX_HEAD(exp)
  79. COMPLEX_BODY(exp)
  80. DCOMPLEX_HEAD(exp)
  81. DCOMPLEX_BODY(exp)
  82. REAL_HEAD(log)
  83. REAL_BODY(log)
  84. COMPLEX_HEAD(log)
  85. COMPLEX_BODY(log)
  86. DCOMPLEX_HEAD(log)
  87. DCOMPLEX_BODY(log)
  88. REAL_HEAD(log10)
  89. REAL_BODY(log10)
  90. REAL_HEAD(sqrt)
  91. REAL_BODY(sqrt)
  92. COMPLEX_HEAD(sqrt)
  93. COMPLEX_BODY(sqrt)
  94. DCOMPLEX_HEAD(sqrt)
  95. DCOMPLEX_BODY(sqrt)
  96. REAL_HEAD(asin)
  97. REAL_BODY(asin)
  98. REAL_HEAD(acos)
  99. REAL_BODY(acos)
  100. REAL_HEAD(atan)
  101. REAL_BODY(atan)
  102. REAL_HEAD(asinh)
  103. REAL_BODY(asinh)
  104. REAL_HEAD(acosh)
  105. REAL_BODY(acosh)
  106. REAL_HEAD(atanh)
  107. REAL_BODY(atanh)
  108. REAL_HEAD(sin)
  109. REAL_BODY(sin)
  110. COMPLEX_HEAD(sin)
  111. COMPLEX_BODY(sin)
  112. DCOMPLEX_HEAD(sin)
  113. DCOMPLEX_BODY(sin)
  114. REAL_HEAD(cos)
  115. REAL_BODY(cos)
  116. COMPLEX_HEAD(cos)
  117. COMPLEX_BODY(cos)
  118. DCOMPLEX_HEAD(cos)
  119. DCOMPLEX_BODY(cos)
  120. REAL_HEAD(tan)
  121. REAL_BODY(tan)
  122. REAL_HEAD(sinh)
  123. REAL_BODY(sinh)
  124. REAL_HEAD(cosh)
  125. REAL_BODY(cosh)
  126. REAL_HEAD(tanh)
  127. REAL_BODY(tanh)
  128. REAL_HEAD(aint)
  129. REAL_BODY(aint)
  130. REAL_HEAD(anint)
  131. REAL_BODY(anint)
  132. ! two argument functions
  133. #define REAL2_HEAD(NAME) \
  134. elemental function _gfortran_f2c_specific__/**/NAME/**/_r4 (p1, p2) result(res);
  135. #define REAL2_BODY(NAME) \
  136. REAL, intent (in) :: p1, p2; \
  137. DOUBLE PRECISION :: res; \
  138. res = NAME (p1, p2); \
  139. end function
  140. REAL2_HEAD(sign)
  141. REAL2_BODY(sign)
  142. REAL2_HEAD(dim)
  143. REAL2_BODY(dim)
  144. REAL2_HEAD(atan2)
  145. REAL2_BODY(atan2)
  146. REAL2_HEAD(mod)
  147. REAL2_BODY(mod)
  148. ! conjg is special-cased because it is not suffixed _c4 but _4
  149. subroutine _gfortran_f2c_specific__conjg_4 (res, parm)
  150. COMPLEX, intent (in) :: parm
  151. COMPLEX, intent (out) :: res
  152. res = conjg (parm)
  153. end subroutine
  154. subroutine _gfortran_f2c_specific__conjg_8 (res, parm)
  155. DOUBLE COMPLEX, intent (in) :: parm
  156. DOUBLE COMPLEX, intent (out) :: res
  157. res = conjg (parm)
  158. end subroutine