| 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 | ```{contents} |
| 12 | --- |
| 13 | local: |
| 14 | --- |
| 15 | ``` |
| 16 | |
| 17 | Intrinsic types are integer, real, complex, character, and logical. |
| 18 | All intrinsic types have a kind type parameter called KIND, |
| 19 | which determines the representation method for the specified type. |
| 20 | The intrinsic type character also has a length type parameter called LEN, |
| 21 | which determines the length of the character string. |
| 22 | |
| 23 | The implementation of `CHARACTER` type in f18 is described |
| 24 | in [Character.md](Character.md). |
| 25 | |
| 26 | ## Supported TYPES and KINDS |
| 27 | |
| 28 | Here are the type and kind combinations supported in f18: |
| 29 | |
| 30 | INTEGER(KIND=1) 8-bit two's-complement integer |
| 31 | INTEGER(KIND=2) 16-bit two's-complement integer |
| 32 | INTEGER(KIND=4) 32-bit two's-complement integer |
| 33 | INTEGER(KIND=8) 64-bit two's-complement integer |
| 34 | INTEGER(KIND=16) 128-bit two's-complement integer |
| 35 | |
| 36 | REAL(KIND=2) 16-bit IEEE 754 binary16 (5e11m) |
| 37 | REAL(KIND=3) 16-bit upper half of 32-bit IEEE 754 binary32 (8e8m) |
| 38 | REAL(KIND=4) 32-bit IEEE 754 binary32 (8e24m) |
| 39 | REAL(KIND=8) 64-bit IEEE 754 binary64 (11e53m) |
| 40 | REAL(KIND=10) 80-bit extended precision with explicit normalization bit (15e64m) |
| 41 | REAL(KIND=16) 128-bit IEEE 754 binary128 (15e113m) |
| 42 | |
| 43 | COMPLEX(KIND=2) Two 16-bit IEEE 754 binary16 |
| 44 | COMPLEX(KIND=3) Two 16-bit upper half of 32-bit IEEE 754 binary32 |
| 45 | COMPLEX(KIND=4) Two 32-bit IEEE 754 binary32 |
| 46 | COMPLEX(KIND=8) Two 64-bit IEEE 754 binary64 |
| 47 | COMPLEX(KIND=10) Two 80-bit extended precisions values |
| 48 | COMPLEX(KIND=16) Two 128-bit IEEE 754 binary128 |
| 49 | |
| 50 | No |
| 51 | [double-double |
| 52 | ](https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format) |
| 53 | quad precision type is supported. |
| 54 | |
| 55 | LOGICAL(KIND=1) 8-bit integer |
| 56 | LOGICAL(KIND=2) 16-bit integer |
| 57 | LOGICAL(KIND=4) 32-bit integer |
| 58 | LOGICAL(KIND=8) 64-bit integer |
| 59 | |
| 60 | No 128-bit logical support. |
| 61 | |
| 62 | ### Defaults kinds |
| 63 | |
| 64 | INTEGER 4 |
| 65 | REAL 4 |
| 66 | COMPLEX 4 |
| 67 | DOUBLE PRECISION 8 |
| 68 | LOGICAL 4 |
| 69 | |
| 70 | #### Modifying the default kind with default-real-8. |
| 71 | REAL 8 |
| 72 | DOUBLE PRECISION 8 |
| 73 | COMPLEX 8 |
| 74 | |
| 75 | #### Modifying the default kind with default-integer-8: |
| 76 | INTEGER 8 |
| 77 | LOGICAL 8 |
| 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.. |