]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/intrinsics/trigd_lib.inc
Update copyright years.
[thirdparty/gcc.git] / libgfortran / intrinsics / trigd_lib.inc
1 /* Stub for defining degree-valued trigonometric functions in libgfortran.
2 Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 Contributed by Steven G. Kargl <kargl@gcc.gnu.org>
4 and Fritz Reese <foreese@gcc.gnu.org>
5
6 This file is part of the GNU Fortran runtime library (libgfortran).
7
8 Libgfortran is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 3 of the License, or (at your option) any later version.
12
13 Libgfortran is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
21
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
26
27 /*
28 This replaces all GMP/MPFR functions used by trigd.inc with native versions.
29 The precision is defined by FTYPE defined before including this file.
30 The module which includes this file must define the following:
31
32 KIND -- floating point kind (4, 8, 10, 16)
33 HAVE_INFINITY_KIND -- defined iff the platform has GFC_REAL_<KIND>_INFINITY
34
35 TINY [optional] -- subtract from 1 under the above condition if set
36 COSD_SMALL [optional] -- for x <= COSD_SMALL, COSD(x) = 1 if set
37 SIND_SMALL [optional] -- for x <= SIND_SMALL, SIND(x) = D2R(x) if set
38 COSD30 -- literal value of COSD(30) to the precision of FTYPE
39 PIO180H -- upper bits of pi/180 for FMA
40 PIO180L -- lower bits of pi/180 for FMA
41
42 */
43
44 /* FTYPE := GFC_REAL_<K> */
45 #define FTYPE CONCAT_EXPAND(GFC_REAL_,KIND)
46
47 /* LITERAL_SUFFIX := GFC_REAL_<K>_LITERAL_SUFFIX */
48 #define LITERAL_SUFFIX CONCAT_EXPAND(FTYPE,_LITERAL_SUFFIX)
49
50 /* LITERAL(X) := GFC_REAL_<K>_LITERAL(X) */
51 #define LITERAL(x) CONCAT_EXPAND(x,LITERAL_SUFFIX)
52
53 #define SIND CONCAT_EXPAND(sind_r, KIND)
54 #define COSD CONCAT_EXPAND(cosd_r, KIND)
55 #define TAND CONCAT_EXPAND(tand_r, KIND)
56
57 #ifdef HAVE_INFINITY_KIND
58 /* GFC_REAL_X_INFINITY */
59 #define INFINITY_KIND CONCAT_EXPAND(FTYPE, _INFINITY)
60 #else
61 /* GFC_REAL_X_HUGE */
62 #define INFINITY_KIND CONCAT_EXPAND(FTYPE, _HUGE)
63 #endif
64
65 #define CONCAT(x,y) x ## y
66 #define CONCAT_EXPAND(x,y) CONCAT(x,y)
67
68 #define COPYSIGN LITERAL(copysign)
69 #define FMOD LITERAL(fmod)
70 #define FABS LITERAL(fabs)
71 #define FMA LITERAL(fma)
72 #define SIN LITERAL(sin)
73 #define COS LITERAL(cos)
74 #define TAN LITERAL(tan)
75
76 #ifdef TINY
77 #define TINY_LITERAL LITERAL(TINY)
78 #endif
79
80 #ifdef COSD_SMALL
81 #define COSD_SMALL_LITERAL LITERAL(COSD_SMALL)
82 #endif
83
84 #ifdef SIND_SMALL
85 #define SIND_SMALL_LITERAL LITERAL(SIND_SMALL)
86 #endif
87
88 #define COSD30_LITERAL LITERAL(COSD30)
89 #define PIO180H_LITERAL LITERAL(PIO180H)
90 #define PIO180L_LITERAL LITERAL(PIO180L)
91
92 #define ITYPE int
93 #define GFC_RND_MODE 0
94 #define RETTYPE FTYPE
95 #define RETURN(x) return (x)
96
97 #define ISFINITE(x) isfinite(x)
98 #define mpfr_init(x) do { } while (0)
99 #define mpfr_init_set_ui(x, v, rnd) (x = (v))
100 #define mpfr_clear(x) do { } while (0)
101 #define mpfr_swap(x, y) do { FTYPE z = y; y = x; x = z; } while (0)
102 #define mpfr_copysign(rop, op1, op2, rnd) rop = COPYSIGN((op1), (op2))
103 #define mpfr_fmod(rop, x, d, rnd) (rop = FMOD((x), (d)))
104 #define mpfr_abs(rop, op, rnd) (rop = FABS(op))
105 #define mpfr_cmp_ld(x, y) ((x) - (y))
106 #define mpfr_cmp_ui(x, n) ((x) - (n))
107 #define mpfr_zero_p(x) ((x) == 0)
108 #define mpfr_set(rop, x, rnd) (rop = (x))
109 #define mpfr_set_zero(rop, s) (rop = COPYSIGN(0, (s)))
110 #define mpfr_set_inf(rop, s) (rop = ((s)*-2 + 1) * INFINITY_KIND)
111 #define mpfr_set_ui(rop, n, rnd) (rop = (n))
112 #define mpfr_set_si(rop, n, rnd) (rop = (n))
113 #define mpfr_set_ld(rop, x, rnd) (rop = (x))
114 #define mpfr_set_si_2exp(rop, op, exp, rnd) (rop = (0x1.p##exp))
115 #define mpfr_get_z(rop, x, rnd) ((rop = (int)(x)), (rop - (x)))
116 #define mpfr_mul(rop, op1, op2, rnd) (rop = ((op1) * (op2)))
117 #define mpfr_sub_d(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
118 #define mpfr_sub_ui(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
119 #define mpfr_sub(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
120 #define mpfr_ui_sub(rop, op1, op2, rnd) (rop = ((op1) - (op2)))
121 #define mpfr_neg(rop, op, rnd) (rop = -(op))
122 #define mpfr_sin(rop, x, rnd) (rop = SIN(x))
123 #define mpfr_cos(rop, x, rnd) (rop = COS(x))
124 #define mpfr_tan(rop, x, rnd) (rop = TAN(x))
125
126 #define mpz_init(n) do { } while (0)
127 #define mpz_clear(x) do { } while (0)
128 #define mpz_cmp_ui(x, y) ((x) - (y))
129 #define mpz_divisible_ui_p(n, d) ((n) % (d) == 0)
130
131 #define D2R(x) (x = FMA((x), PIO180H_LITERAL, (x) * PIO180L_LITERAL))
132
133 #define SET_COSD30(x) (x = COSD30_LITERAL)
134
135 #ifdef SIND
136 extern FTYPE SIND (FTYPE);
137 export_proto (SIND);
138 #endif
139
140 #ifdef COSD
141 extern FTYPE COSD (FTYPE);
142 export_proto (COSD);
143 #endif
144
145 #ifdef TAND
146 extern FTYPE TAND (FTYPE);
147 export_proto (TAND);
148 #endif
149
150 #include "trigd.inc"
151
152 #undef FTYPE
153 #undef LITERAL_SUFFIX
154 #undef LITERAL
155 #undef CONCAT3
156 #undef CONCAT3_EXPAND
157 #undef CONCAT
158 #undef CONCAT_EXPAND
159 #undef SIND
160 #undef COSD
161 #undef TAND
162 #undef INFINITY_KIND
163
164 #undef COPYSIGN
165 #undef FMOD
166 #undef FABS
167 #undef FMA
168 #undef SIN
169 #undef COS
170 #undef TAN
171
172 #undef TINY_LITERAL
173 #undef COSD_SMALL_LITERAL
174 #undef SIND_SMALL_LITERAL
175 #undef COSD30_LITERAL
176 #undef PIO180H_LITERAL
177 #undef PIO180L_LITERAL
178
179 #undef ITYPE
180 #undef GFC_RND_MODE
181 #undef RETTYPE
182 #undef RETURN
183
184 #undef ISFINITE
185 #undef mpfr_signbit
186
187 #undef mpfr_init
188 #undef mpfr_init_set_ui
189 #undef mpfr_clear
190 #undef mpfr_swap
191 #undef mpfr_fmod
192 #undef mpfr_abs
193 #undef mpfr_cmp_ld
194 #undef mpfr_cmp_ui
195 #undef mpfr_zero_p
196 #undef mpfr_set
197 #undef mpfr_set_zero
198 #undef mpfr_set_inf
199 #undef mpfr_set_ui
200 #undef mpfr_set_si
201 #undef mpfr_set_ld
202 #undef mpfr_set_si_2exp
203 #undef mpfr_get_z
204 #undef mpfr_mul_si
205 #undef mpfr_sub_d
206 #undef mpfr_sub_ui
207 #undef mpfr_sub
208 #undef mpfr_ui_sub
209 #undef mpfr_neg
210 #undef mpfr_sin
211 #undef mpfr_cos
212 #undef mpfr_tan
213
214 #undef mpz_init
215 #undef mpz_clear
216 #undef mpz_cmp_ui
217 #undef mpz_divisible_ui_p
218
219 #undef FMA
220 #undef D2R
221
222 #undef SET_COSD30
223
224
225 /* vim: set ft=c: */