]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/ISO_Fortran_binding.h
rs6000: Add load density heuristic
[thirdparty/gcc.git] / libgfortran / ISO_Fortran_binding.h
CommitLineData
bbf18dc5 1/* Declarations for ISO Fortran binding.
99dee823 2 Copyright (C) 2018-2021 Free Software Foundation, Inc.
bbf18dc5
PT
3 Contributed by Daniel Celis Garza <celisdanieljr@gmail.com>
4
5This file is part of the GNU Fortran runtime library (libgfortran).
6
7Libgfortran is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12Libgfortran is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
25
26#ifndef ISO_FORTRAN_BINDING_H
27#define ISO_FORTRAN_BINDING_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <stddef.h> /* Standard ptrdiff_t tand size_t. */
34#include <stdint.h> /* Integer types. */
13beaf9e 35#include <float.h> /* Macros for floating-point type characteristics. */
bbf18dc5
PT
36
37/* Constants, defined as macros. */
38#define CFI_VERSION 1
39#define CFI_MAX_RANK 15
40
41/* Attributes. */
42#define CFI_attribute_pointer 0
43#define CFI_attribute_allocatable 1
44#define CFI_attribute_other 2
45
46/* Error codes.
fef67987
SL
47 Note that CFI_FAILURE and CFI_INVALID_STRIDE are specific to GCC
48 and not part of the Fortran standard */
bbf18dc5
PT
49#define CFI_SUCCESS 0
50#define CFI_FAILURE 1
51#define CFI_ERROR_BASE_ADDR_NULL 2
52#define CFI_ERROR_BASE_ADDR_NOT_NULL 3
53#define CFI_INVALID_ELEM_LEN 4
54#define CFI_INVALID_RANK 5
55#define CFI_INVALID_TYPE 6
56#define CFI_INVALID_ATTRIBUTE 7
57#define CFI_INVALID_EXTENT 8
58#define CFI_INVALID_STRIDE 9
59#define CFI_INVALID_DESCRIPTOR 10
60#define CFI_ERROR_MEM_ALLOCATION 11
61#define CFI_ERROR_OUT_OF_BOUNDS 12
62
63/* CFI type definitions. */
64typedef ptrdiff_t CFI_index_t;
65typedef int8_t CFI_rank_t;
66typedef int8_t CFI_attribute_t;
67typedef int16_t CFI_type_t;
68
69/* CFI_dim_t. */
70typedef struct CFI_dim_t
71 {
72 CFI_index_t lower_bound;
73 CFI_index_t extent;
74 CFI_index_t sm;
75 }
76CFI_dim_t;
77
78/* CFI_cdesc_t, C descriptors are cast to this structure as follows:
79 CFI_CDESC_T(CFI_MAX_RANK) foo;
80 CFI_cdesc_t * bar = (CFI_cdesc_t *) &foo;
81 */
82typedef struct CFI_cdesc_t
83 {
84 void *base_addr;
85 size_t elem_len;
86 int version;
87 CFI_rank_t rank;
88 CFI_attribute_t attribute;
89 CFI_type_t type;
90 CFI_dim_t dim[];
91 }
92CFI_cdesc_t;
93
94/* CFI_CDESC_T with an explicit type. */
95#define CFI_CDESC_TYPE_T(r, base_type) \
96 struct { \
97 base_type *base_addr; \
98 size_t elem_len; \
99 int version; \
100 CFI_rank_t rank; \
101 CFI_attribute_t attribute; \
102 CFI_type_t type; \
103 CFI_dim_t dim[r]; \
104 }
105#define CFI_CDESC_T(r) CFI_CDESC_TYPE_T (r, void)
106
107/* CFI function declarations. */
108extern void *CFI_address (const CFI_cdesc_t *, const CFI_index_t []);
109extern int CFI_allocate (CFI_cdesc_t *, const CFI_index_t [], const CFI_index_t [],
110 size_t);
111extern int CFI_deallocate (CFI_cdesc_t *);
112extern int CFI_establish (CFI_cdesc_t *, void *, CFI_attribute_t, CFI_type_t, size_t,
113 CFI_rank_t, const CFI_index_t []);
114extern int CFI_is_contiguous (const CFI_cdesc_t *);
115extern int CFI_section (CFI_cdesc_t *, const CFI_cdesc_t *, const CFI_index_t [],
116 const CFI_index_t [], const CFI_index_t []);
117extern int CFI_select_part (CFI_cdesc_t *, const CFI_cdesc_t *, size_t, size_t);
118extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);
119
120/* Types and kind numbers. Allows bitwise and to reveal the intrinsic type of a kind type. It also allows us to find the kind parameter by inverting the bit-shift equation.
121 CFI_type_kind_shift = 8
122 CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
123 CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0
124 CFI_type_example = CFI_intrinsic_type + (CFI_type_kind << CFI_type_kind_shift)
125 Defining the CFI_type_example.
126 CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0 << CFI_type_kind_shift
127 -------------------------
128 1 0 0 0 0 0 0 0 0 0 0 0 +
129 CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
130 -------------------------
131 CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0
132 Finding the intrinsic type with the logical mask.
133 CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 &
134 CFI_type_mask = 0 0 0 0 1 1 1 1 1 1 1 1
135 -------------------------
136 CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
137 Using the intrinsic type and kind shift to find the kind value of the type.
138 CFI_type_kind = (CFI_type_example - CFI_intrinsic_type) >> CFI_type_kind_shift
139 CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 -
140 CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
141 -------------------------
142 1 0 0 0 0 0 0 0 0 0 0 0 >> CFI_type_kind_shift
143 -------------------------
144 CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0
145 */
146#define CFI_type_mask 0xFF
147#define CFI_type_kind_shift 8
148
149/* Intrinsic types. Their kind number defines their storage size. */
150#define CFI_type_Integer 1
151#define CFI_type_Logical 2
152#define CFI_type_Real 3
153#define CFI_type_Complex 4
154#define CFI_type_Character 5
155
93b6b2f6
SL
156/* Types with no kind. FIXME: GFC descriptors currently use BT_VOID for
157 both C_PTR and C_FUNPTR, so we have no choice but to make them
158 identical here too. That can potentially break on targets where
159 function and data pointers have different sizes/representations.
160 See PR 100915. */
bbf18dc5
PT
161#define CFI_type_struct 6
162#define CFI_type_cptr 7
93b6b2f6 163#define CFI_type_cfunptr CFI_type_cptr
bbf18dc5
PT
164#define CFI_type_other -1
165
166/* Types with kind parameter.
fef67987
SL
167 The kind parameter represents the type's byte size. The exception is
168 real kind = 10, which has byte size of 128 bits but 80 bit precision.
169 Complex variables are double the byte size of their real counterparts.
170 The ucs4_char matches wchar_t if sizeof (wchar_t) == 4.
bbf18dc5
PT
171 */
172#define CFI_type_char (CFI_type_Character + (1 << CFI_type_kind_shift))
173#define CFI_type_ucs4_char (CFI_type_Character + (4 << CFI_type_kind_shift))
174
175/* C-Fortran Interoperability types. */
fef67987
SL
176#define CFI_type_signed_char (CFI_type_Integer + (sizeof (char) << CFI_type_kind_shift))
177#define CFI_type_short (CFI_type_Integer + (sizeof (short) << CFI_type_kind_shift))
178#define CFI_type_int (CFI_type_Integer + (sizeof (int) << CFI_type_kind_shift))
179#define CFI_type_long (CFI_type_Integer + (sizeof (long) << CFI_type_kind_shift))
180#define CFI_type_long_long (CFI_type_Integer + (sizeof (long long) << CFI_type_kind_shift))
181#define CFI_type_size_t (CFI_type_Integer + (sizeof (size_t) << CFI_type_kind_shift))
182#define CFI_type_int8_t (CFI_type_Integer + (sizeof (int8_t) << CFI_type_kind_shift))
183#define CFI_type_int16_t (CFI_type_Integer + (sizeof (int16_t) << CFI_type_kind_shift))
184#define CFI_type_int32_t (CFI_type_Integer + (sizeof (int32_t) << CFI_type_kind_shift))
185#define CFI_type_int64_t (CFI_type_Integer + (sizeof (int64_t) << CFI_type_kind_shift))
186#define CFI_type_int_least8_t (CFI_type_Integer + (sizeof (int_least8_t) << CFI_type_kind_shift))
187#define CFI_type_int_least16_t (CFI_type_Integer + (sizeof (int_least16_t) << CFI_type_kind_shift))
188#define CFI_type_int_least32_t (CFI_type_Integer + (sizeof (int_least32_t) << CFI_type_kind_shift))
189#define CFI_type_int_least64_t (CFI_type_Integer + (sizeof (int_least64_t) << CFI_type_kind_shift))
190#define CFI_type_int_fast8_t (CFI_type_Integer + (sizeof (int_fast8_t) << CFI_type_kind_shift))
191#define CFI_type_int_fast16_t (CFI_type_Integer + (sizeof (int_fast16_t) << CFI_type_kind_shift))
192#define CFI_type_int_fast32_t (CFI_type_Integer + (sizeof (int_fast32_t) << CFI_type_kind_shift))
193#define CFI_type_int_fast64_t (CFI_type_Integer + (sizeof (int_fast64_t) << CFI_type_kind_shift))
194#define CFI_type_intmax_t (CFI_type_Integer + (sizeof (intmax_t) << CFI_type_kind_shift))
195#define CFI_type_intptr_t (CFI_type_Integer + (sizeof (intptr_t) << CFI_type_kind_shift))
196#define CFI_type_ptrdiff_t (CFI_type_Integer + (sizeof (ptrdiff_t) << CFI_type_kind_shift))
197#define CFI_type_Bool (CFI_type_Logical + (sizeof (_Bool) << CFI_type_kind_shift))
198#define CFI_type_float (CFI_type_Real + (sizeof (float) << CFI_type_kind_shift))
199#define CFI_type_double (CFI_type_Real + (sizeof (double) << CFI_type_kind_shift))
200#define CFI_type_float_Complex (CFI_type_Complex + (sizeof (float) << CFI_type_kind_shift))
201#define CFI_type_double_Complex (CFI_type_Complex + (sizeof (double) << CFI_type_kind_shift))
13beaf9e
SL
202
203/* If GCC supports int128_t on this target, it predefines
204 __SIZEOF_INT128__ to 16. */
205#if defined(__SIZEOF_INT128__)
206#if (__SIZEOF_INT128__ == 16)
207#define CFI_type_int128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
208#define CFI_type_int_least128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
209#define CFI_type_int_fast128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
210#else
211#error "Can't determine kind of int128_t"
212#endif
213#else
214#define CFI_type_int128_t -2
215#define CFI_type_int_least128_t -2
216#define CFI_type_int_fast128_t -2
217#endif
218
219/* The situation with long double support is more complicated; we need to
220 examine the type in more detail to figure out its kind. */
221
222/* Long double is the same kind as double. */
223#if (LDBL_MANT_DIG == DBL_MANT_DIG \
224 && LDBL_MIN_EXP == DBL_MIN_EXP \
225 && LDBL_MAX_EXP == DBL_MAX_EXP)
226#define CFI_type_long_double CFI_type_double
227#define CFI_type_long_double_Complex CFI_type_double_Complex
228
229/* This is the 80-bit encoding on x86; Fortran assigns it kind 10. */
230#elif (LDBL_MANT_DIG == 64 \
231 && LDBL_MIN_EXP == -16381 \
232 && LDBL_MAX_EXP == 16384)
233#define CFI_type_long_double (CFI_type_Real + (10 << CFI_type_kind_shift))
234#define CFI_type_long_double_Complex (CFI_type_Complex + (10 << CFI_type_kind_shift))
235
236/* This is the IEEE 128-bit encoding, same as float128. */
237#elif (LDBL_MANT_DIG == 113 \
238 && LDBL_MIN_EXP == -16381 \
239 && LDBL_MAX_EXP == 16384)
240#define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift))
241#define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
242
243/* This is the IBM128 encoding used on PowerPC; also assigned kind 16. */
244#elif (LDBL_MANT_DIG == 106 \
245 && LDBL_MIN_EXP == -968 \
246 && LDBL_MAX_EXP == 1024)
247#define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift))
248#define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
249#define CFI_no_float128 1
250
251/* It's a bug if we get here. If you've got a target that has some other
252 long double encoding, you need add something here for Fortran to
253 recognize it. */
254#else
255#error "Can't determine kind of long double"
256#endif
257
258/* Similarly for __float128. This always refers to the IEEE encoding
259 and not some other 128-bit representation, so if we already used
260 kind 16 for a non-IEEE representation, this one must be unsupported
261 in Fortran even if it's available in C. */
262#if (!defined (CFI_no_float128) \
263 && defined(__FLT128_MANT_DIG__) && __FLT128_MANT_DIG__ == 113 \
264 && defined(__FLT128_MIN_EXP__) && __FLT128_MIN_EXP__ == -16381 \
265 && defined(__FLT128_MAX_EXP__) && __FLT128_MAX_EXP__ == 16384)
266#define CFI_type_float128 (CFI_type_Real + (16 << CFI_type_kind_shift))
267#define CFI_type_float128_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
268#else
269#define CFI_type_float128 -2
270#define CFI_type_float128_Complex -2
271#endif
272
273#ifdef __cplusplus
274}
275#endif
276
277#endif /* ISO_FORTRAN_BINDING_H */