Skip to content

[CLANG] Full support of complex multiplication and division.#81514

Merged
zahiraam merged 23 commits into
llvm:mainfrom
zahiraam:ComplexRange
Mar 20, 2024
Merged

[CLANG] Full support of complex multiplication and division.#81514
zahiraam merged 23 commits into
llvm:mainfrom
zahiraam:ComplexRange

Conversation

@zahiraam

@zahiraam zahiraam commented Feb 12, 2024

Copy link
Copy Markdown
Contributor

In clang there are two options -f[no]cx-limited-range and -f[no]cx-fortran-rules that control the range of complex multiplication and division. However, it is unclear how these options interact with one another. For instance, what should happen when the users compile with -fcx-fortran-rules -fno-cx-limited-range or -fcx-limited-range -fno-cx-fortran-rules?

In this patch we are introducing a new option to solve the issue and give a greater flexibility to the user to control the behavior of the compiler when performing multiplication and division of complex floating-point values.

-fcomplex-arihmetic=[full|improved|promoted|basic]

full: Implementation of complex division and multiplication using a call to runtime library functions (generally the case, but the BE might sometimes replace the library call if it knows enough about the potential range of the inputs). Overflow and non-finite values are handled by the library implementation. For the case of multiplication overflow will occur in accordance with normal floating-point rules. This is the default value.

improved: Implementation of complex division using the Smith algorithm at source precision. Smith's algorithm for complex division. See SMITH, R. L. Algorithm 116: Complex division. Commun. ACM 5, 8 (1962). This value offers improved handling for overflow in intermediate calculations, but overflow may occur. NaN and infinite values are not handled in some cases.

promoted: Implementation of complex division using algebraic formulas at higher precision. Overflow is handled. Non-finite values are handled in some cases. If the target does not have native support for a higher precision data type, the implementation for the complex operation using the Smith algorithm will be used. Overflow may still occur in some cases. NaN and infinite values are not handled.

basic: Implementation of complex division and multiplication using algebraic formulas at source precision. No special handling to avoid overflow. NaN and infinite values are not handled.

fcx-limited-range will alias -fcomplex-arithmetic=basic
-fcx-fortran-rules will alias -fcomplex-arithmetic=improved
-fno-cx-limited-range and -fno-cx-fortran-rules will alias -fcomplex-arithmetic=full

The complex division and multiplication will be implemented as follows depending on the option used.

<style> </style>
-fcomplex-arithmetic div mul
basic algebraic form algebraic form
improved smith's algorithm algebraic form
full libcall libcall + nan processing
promoted algebraic form + higher precision algebraic form

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants