From ee8ce36ba651ce93533c380f2427fed9327e0434 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Fri, 3 Oct 2025 13:30:57 -0700 Subject: [PATCH 1/4] [Flang][Docs] Clean up flang/docs/IntrinsicTypes.md documentation Light cleanup of the IntrinsicTypes.md documentation. --- flang/docs/IntrinsicTypes.md | 130 ++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 63 deletions(-) diff --git a/flang/docs/IntrinsicTypes.md b/flang/docs/IntrinsicTypes.md index 0fee1c3870245..7ab5aa2d70ab8 100644 --- a/flang/docs/IntrinsicTypes.md +++ b/flang/docs/IntrinsicTypes.md @@ -25,90 +25,94 @@ in [Character.md](Character.md). ## Supported TYPES and KINDS -Here are the type and kind combinations supported in f18: - -INTEGER(KIND=1) 8-bit two's-complement integer -INTEGER(KIND=2) 16-bit two's-complement integer -INTEGER(KIND=4) 32-bit two's-complement integer -INTEGER(KIND=8) 64-bit two's-complement integer -INTEGER(KIND=16) 128-bit two's-complement integer - -REAL(KIND=2) 16-bit IEEE 754 binary16 (5e11m) -REAL(KIND=3) 16-bit upper half of 32-bit IEEE 754 binary32 (8e8m) -REAL(KIND=4) 32-bit IEEE 754 binary32 (8e24m) -REAL(KIND=8) 64-bit IEEE 754 binary64 (11e53m) -REAL(KIND=10) 80-bit extended precision with explicit normalization bit (15e64m) -REAL(KIND=16) 128-bit IEEE 754 binary128 (15e113m) - -COMPLEX(KIND=2) Two 16-bit IEEE 754 binary16 -COMPLEX(KIND=3) Two 16-bit upper half of 32-bit IEEE 754 binary32 -COMPLEX(KIND=4) Two 32-bit IEEE 754 binary32 -COMPLEX(KIND=8) Two 64-bit IEEE 754 binary64 -COMPLEX(KIND=10) Two 80-bit extended precisions values -COMPLEX(KIND=16) Two 128-bit IEEE 754 binary128 - -No -[double-double -](https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format) +f18 supports the following type and kind combinations: + +| Type | Description | +| :--: | :---------: | +| INTEGER(KIND=1) | 8-bit two's-complement integer | +| INTEGER(KIND=2) | 16-bit two's-complement integer | +| INTEGER(KIND=4) | 32-bit two's-complement integer | +| INTEGER(KIND=8) | 64-bit two's-complement integer | +| INTEGER(KIND=16) | 128-bit two's-complement integer | +| REAL(KIND=2) | 16-bit IEEE 754 binary16 (5e11m) | +| REAL(KIND=3) | 16-bit upper half of 32-bit IEEE 754 binary32 (8e8m) | +| REAL(KIND=4) | 32-bit IEEE 754 binary32 (8e24m) | +| REAL(KIND=8) | 64-bit IEEE 754 binary64 (11e53m) | +| REAL(KIND=10) | 80-bit extended precision with explicit normalization bit (15e64m) | +| REAL(KIND=16) | 128-bit IEEE 754 binary128 (15e113m) | +| COMPLEX(KIND=2) | Two 16-bit IEEE 754 binary16 | +| COMPLEX(KIND=3) | Two 16-bit upper half of 32-bit IEEE 754 binary32 | +| COMPLEX(KIND=4) | Two 32-bit IEEE 754 binary32 | +| COMPLEX(KIND=8) | Two 64-bit IEEE 754 binary64 | +| COMPLEX(KIND=10) | Two 80-bit extended precisions values | +| COMPLEX(KIND=16) | Two 128-bit IEEE 754 binary128 | +| LOGICAL(KIND=1) | 8-bit integer | +| LOGICAL(KIND=2) | 16-bit integer | +| LOGICAL(KIND=4) | 32-bit integer | +| LOGICAL(KIND=8) | 64-bit integer | + +* No [double-double](https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format) quad precision type is supported. +* No 128-bit logical support. -LOGICAL(KIND=1) 8-bit integer -LOGICAL(KIND=2) 16-bit integer -LOGICAL(KIND=4) 32-bit integer -LOGICAL(KIND=8) 64-bit integer +### Defaults kinds -No 128-bit logical support. +f18 defaults to the following kinds for these types: -### Defaults kinds +* `INTEGER` 4 +* `REAL` 4 +* `COMPLEX` 4 +* `DOUBLE PRECISION` 8 +* `LOGICAL` 4 -INTEGER 4 -REAL 4 -COMPLEX 4 -DOUBLE PRECISION 8 -LOGICAL 4 +Modules compiled with different default-real and default-integer kinds +may be freely mixed. Module files encode the kind value for every entity. #### Modifying the default kind with default-real-8. -REAL 8 -DOUBLE PRECISION 8 -COMPLEX 8 + +* `REAL` 8 +* `DOUBLE PRECISION` 8 +* `COMPLEX` 8 #### Modifying the default kind with default-integer-8: -INTEGER 8 -LOGICAL 8 -Modules compiled with different default-real and default-integer kinds -may be freely mixed. -Module files encode the kind value for every entity. +* `INTEGER` 8 +* `LOGICAL` 8 ## Representation of LOGICAL variables -The default logical is `LOGICAL(KIND=4)`. - -Logical literal constants with kind 1, 2, 4, and 8 -share the following characteristics: -.TRUE. is represented as 1_kind -.FALSE. is represented as 0_kind +The Fortran standard specifies that a logical has two values, `.TRUE.` and +`.FALSE.`, but does not specify their internal representation. -Tests for true is *integer value is not zero*. +Flang specifies that logical literal constants with `KIND=[1|2|4|8]` share the +following characteristics: -The implementation matches gfortran. +* `.TRUE.` is `1_kind`. +* `.FALSE.` is `0_kind`. +* A true test is ` .NE. 0_kind`. -Programs should not use integer values in LOGICAL contexts or -use LOGICAL values to interface with other languages. +Programs should not use integer values in LOGICAL contexts or use LOGICAL values +to interface with other languages. ### Representations of LOGICAL variables in other compilers +#### GNU gfortran + +* `.TRUE.` is `1_kind`. +* `.FALSE.` is `0_kind`. +* A true test is ` .NE. 0_kind`. + #### Intel ifort / NVIDA nvfortran / PGI pgf90 -.TRUE. is represented as -1_kind -.FALSE. is represented as 0_kind -Any other values result in undefined behavior. -Values with a low-bit set are treated as .TRUE.. -Values with a low-bit clear are treated as .FALSE.. +* `.TRUE.` is `-1_kind`. +* `.FALSE.` is `0_kind`. +* Any other values result in undefined behavior. +* Values with a low-bit set are treated as `.TRUE.`. +* Values with a low-bit clear are treated as `.FALSE.`. #### IBM XLF -.TRUE. is represented as 1_kind -.FALSE. is represented as 0_kind -Values with a low-bit set are treated as .TRUE.. -Values with a low-bit clear are treated as .FALSE.. +* `.TRUE.` is `1_kind`. +* `.FALSE.` is `0_kind`. +* Values with a low-bit set are treated as `.TRUE.`. +* Values with a low-bit clear are treated as `.FALSE.`. From 27c7dfafec4223ff284a9f58e72aca70c0dfeebf Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Fri, 3 Oct 2025 13:37:07 -0700 Subject: [PATCH 2/4] Fix some whitespace issues. --- flang/docs/IntrinsicTypes.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flang/docs/IntrinsicTypes.md b/flang/docs/IntrinsicTypes.md index 7ab5aa2d70ab8..8476eaec9ced0 100644 --- a/flang/docs/IntrinsicTypes.md +++ b/flang/docs/IntrinsicTypes.md @@ -30,7 +30,7 @@ f18 supports the following type and kind combinations: | Type | Description | | :--: | :---------: | | INTEGER(KIND=1) | 8-bit two's-complement integer | -| INTEGER(KIND=2) | 16-bit two's-complement integer | +| INTEGER(KIND=2) | 16-bit two's-complement integer | | INTEGER(KIND=4) | 32-bit two's-complement integer | | INTEGER(KIND=8) | 64-bit two's-complement integer | | INTEGER(KIND=16) | 128-bit two's-complement integer | @@ -106,13 +106,13 @@ to interface with other languages. * `.TRUE.` is `-1_kind`. * `.FALSE.` is `0_kind`. -* Any other values result in undefined behavior. -* Values with a low-bit set are treated as `.TRUE.`. -* Values with a low-bit clear are treated as `.FALSE.`. +* Any other values result in undefined behavior. +* Values with a low-bit set are treated as `.TRUE.`. +* Values with a low-bit clear are treated as `.FALSE.`. #### IBM XLF * `.TRUE.` is `1_kind`. * `.FALSE.` is `0_kind`. -* Values with a low-bit set are treated as `.TRUE.`. -* Values with a low-bit clear are treated as `.FALSE.`. +* Values with a low-bit set are treated as `.TRUE.`. +* Values with a low-bit clear are treated as `.FALSE.`. From 9f3b0302c21950e5317745a87bf8763d672840cc Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Fri, 3 Oct 2025 13:39:50 -0700 Subject: [PATCH 3/4] Fix more whitespace issues. --- flang/docs/IntrinsicTypes.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flang/docs/IntrinsicTypes.md b/flang/docs/IntrinsicTypes.md index 8476eaec9ced0..1884de30889d1 100644 --- a/flang/docs/IntrinsicTypes.md +++ b/flang/docs/IntrinsicTypes.md @@ -34,7 +34,7 @@ f18 supports the following type and kind combinations: | INTEGER(KIND=4) | 32-bit two's-complement integer | | INTEGER(KIND=8) | 64-bit two's-complement integer | | INTEGER(KIND=16) | 128-bit two's-complement integer | -| REAL(KIND=2) | 16-bit IEEE 754 binary16 (5e11m) | +| REAL(KIND=2) | 16-bit IEEE 754 binary16 (5e11m) | | REAL(KIND=3) | 16-bit upper half of 32-bit IEEE 754 binary32 (8e8m) | | REAL(KIND=4) | 32-bit IEEE 754 binary32 (8e24m) | | REAL(KIND=8) | 64-bit IEEE 754 binary64 (11e53m) | @@ -43,13 +43,13 @@ f18 supports the following type and kind combinations: | COMPLEX(KIND=2) | Two 16-bit IEEE 754 binary16 | | COMPLEX(KIND=3) | Two 16-bit upper half of 32-bit IEEE 754 binary32 | | COMPLEX(KIND=4) | Two 32-bit IEEE 754 binary32 | -| COMPLEX(KIND=8) | Two 64-bit IEEE 754 binary64 | +| COMPLEX(KIND=8) | Two 64-bit IEEE 754 binary64 | | COMPLEX(KIND=10) | Two 80-bit extended precisions values | | COMPLEX(KIND=16) | Two 128-bit IEEE 754 binary128 | | LOGICAL(KIND=1) | 8-bit integer | -| LOGICAL(KIND=2) | 16-bit integer | +| LOGICAL(KIND=2) | 16-bit integer | | LOGICAL(KIND=4) | 32-bit integer | -| LOGICAL(KIND=8) | 64-bit integer | +| LOGICAL(KIND=8) | 64-bit integer | * No [double-double](https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format) quad precision type is supported. @@ -59,9 +59,9 @@ quad precision type is supported. f18 defaults to the following kinds for these types: -* `INTEGER` 4 -* `REAL` 4 -* `COMPLEX` 4 +* `INTEGER` 4 +* `REAL` 4 +* `COMPLEX` 4 * `DOUBLE PRECISION` 8 * `LOGICAL` 4 @@ -70,8 +70,8 @@ may be freely mixed. Module files encode the kind value for every entity. #### Modifying the default kind with default-real-8. -* `REAL` 8 -* `DOUBLE PRECISION` 8 +* `REAL` 8 +* `DOUBLE PRECISION` 8 * `COMPLEX` 8 #### Modifying the default kind with default-integer-8: From 2194d835d0ffa90eba85124bf96b3d3c3166d3b4 Mon Sep 17 00:00:00 2001 From: Cameron McInally Date: Mon, 6 Oct 2025 15:19:10 -0700 Subject: [PATCH 4/4] Hightlight some keywords and spell out `-fdefault-[real|integer]-`. --- flang/docs/IntrinsicTypes.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/flang/docs/IntrinsicTypes.md b/flang/docs/IntrinsicTypes.md index 1884de30889d1..d71c094f70f3b 100644 --- a/flang/docs/IntrinsicTypes.md +++ b/flang/docs/IntrinsicTypes.md @@ -14,13 +14,13 @@ local: --- ``` -Intrinsic types are integer, real, complex, character, and logical. -All intrinsic types have a kind type parameter called KIND, +Intrinsic types are `INTEGER`, `REAL`, `COMPLEX`, `CHARACTER`, and `LOGICAL`. +All intrinsic types have a kind type parameter called `KIND`, which determines the representation method for the specified type. -The intrinsic type character also has a length type parameter called LEN, +The intrinsic type character also has a length type parameter called `LEN`, which determines the length of the character string. -The implementation of `CHARACTER` type in f18 is described +The implementation of the `CHARACTER` type in f18 is described in [Character.md](Character.md). ## Supported TYPES and KINDS @@ -65,16 +65,17 @@ f18 defaults to the following kinds for these types: * `DOUBLE PRECISION` 8 * `LOGICAL` 4 -Modules compiled with different default-real and default-integer kinds -may be freely mixed. Module files encode the kind value for every entity. +Modules compiled with different `-fdefault-real-` and +`-f-default-integer-` may be freely mixed. Module files encode the kind +value for every entity. -#### Modifying the default kind with default-real-8. +#### Modifying the default kind with -fdefault-real-8: * `REAL` 8 * `DOUBLE PRECISION` 8 * `COMPLEX` 8 -#### Modifying the default kind with default-integer-8: +#### Modifying the default kind with -fdefault-integer-8: * `INTEGER` 8 * `LOGICAL` 8