Skip to content

Commit 9d24eba

Browse files
committed
[flang] Document the Intrinsic Types
Describe the built-in integer, real, complex and logical types implemented in flang, capturing the as-implemented characteristics. Differential Revision: https://reviews.llvm.org/D129658
1 parent 2d5d6c3 commit 9d24eba

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

flang/docs/IntrinsicTypes.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<!--===- docs/IntrinsicTypes.md
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+
9+
# Implementation of `Intrinsic` types in f18
10+
11+
```eval_rst
12+
.. contents::
13+
:local:
14+
```
15+
16+
Intrinsic types are integer, real, complex, character, and logical.
17+
All intrinsic types have a kind type parameter called KIND,
18+
which determines the representation method for the specified type.
19+
The intrinsic type character also has a length type parameter called LEN,
20+
which determines the length of the character string.
21+
22+
The implementation of `CHARACTER` type in f18 is described
23+
in [Character.md](Character.md).
24+
25+
## Supported TYPES and KINDS
26+
27+
Here are the type and kind combinations supported in f18:
28+
29+
INTEGER(KIND=1) 8-bit two's-complement integer
30+
INTEGER(KIND=2) 16-bit two's-complement integer
31+
INTEGER(KIND=4) 32-bit two's-complement integer
32+
INTEGER(KIND=8) 64-bit two's-complement integer
33+
INTEGER(KIND=16) 128-bit two's-complement integer
34+
35+
REAL(KIND=2) 16-bit IEEE 754 binary16 (5e11m)
36+
REAL(KIND=3) 16-bit upper half of 32-bit IEEE 754 binary32 (8e8m)
37+
REAL(KIND=4) 32-bit IEEE 754 binary32 (8e24m)
38+
REAL(KIND=8) 64-bit IEEE 754 binary64 (11e53m)
39+
REAL(KIND=10) 80-bit extended precision with explicit normalization bit (15e64m)
40+
REAL(KIND=16) 128-bit IEEE 754 binary128 (15e113m)
41+
42+
COMPLEX(KIND=2) Two 16-bit IEEE 754 binary16
43+
COMPLEX(KIND=3) Two 16-bit upper half of 32-bit IEEE 754 binary32
44+
COMPLEX(KIND=4) Two 32-bit IEEE 754 binary32
45+
COMPLEX(KIND=8) Two 64-bit IEEE 754 binary64
46+
COMPLEX(KIND=10) Two 80-bit extended precisions values
47+
COMPLEX(KIND=16) Two 128-bit IEEE 754 binary128
48+
49+
No
50+
[double-double
51+
](https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format)
52+
quad precision type is supported.
53+
54+
LOGICAL(KIND=1) 8-bit integer
55+
LOGICAL(KIND=2) 16-bit integer
56+
LOGICAL(KIND=4) 32-bit integer
57+
LOGICAL(KIND=8) 64-bit integer
58+
59+
No 128-bit logical support.
60+
61+
### Defaults kinds
62+
63+
INTEGER 4
64+
REAL 4
65+
COMPLEX 4
66+
DOUBLE PRECISION 8
67+
LOGICAL 4
68+
69+
#### Modifying the default kind with default-real-8.
70+
REAL 8
71+
DOUBLE PRECISION 8
72+
COMPLEX 8
73+
74+
#### Modifying the default kind with default-integer-8:
75+
INTEGER 8
76+
77+
There is no option to modify the default logical kind.
78+
79+
Modules compiled with different default-real and default-integer kinds
80+
may be freely mixed.
81+
Module files encode the kind value for every entity.
82+
83+
## Representation of LOGICAL variables
84+
85+
The default logical is `LOGICAL(KIND=4)`.
86+
87+
Logical literal constants with kind 1, 2, 4, and 8
88+
share the following characteristics:
89+
.TRUE. is represented as 1_kind
90+
.FALSE. is represented as 0_kind
91+
92+
Tests for true is *integer value is not zero*.
93+
94+
The implementation matches gfortran.
95+
96+
Programs should not use integer values in LOGICAL contexts or
97+
use LOGICAL values to interface with other languages.
98+
99+
### Representations of LOGICAL variables in other compilers
100+
101+
##### Intel ifort / NVIDA nvfortran / PGI pgf90
102+
.TRUE. is represented as -1_kind
103+
.FALSE. is represented as 0_kind
104+
Any other values result in undefined behavior.
105+
106+
Values with a low-bit set are treated as .TRUE..
107+
Values with a low-bit clear are treated as .FALSE..
108+
109+
##### IBM XLF
110+
.TRUE. is represented as 1_kind
111+
.FALSE. is represented as 0_kind
112+
113+
Values with a low-bit set are treated as .TRUE..
114+
Values with a low-bit clear are treated as .FALSE..

flang/docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ on how to get in touch with us and to learn more about the current status.
5050
FortranLLVMTestSuite
5151
IORuntimeInternals
5252
Intrinsics
53+
IntrinsicTypes
5354
LabelResolution
5455
ModFiles
5556
OpenMP-4.5-grammar.md

0 commit comments

Comments
 (0)