[AAPCS64] Clarify how __bf16 affects HFAs#314
Merged
smithp35 merged 1 commit intoARM-software:mainfrom Apr 29, 2025
Merged
Conversation
Currently, it's not completely clear whether a struct containing a
mixture of different 16-bit floating point types is a Homogeneous
Aggregate or not:
struct foo {
__fp16 a;
__bf16 b;
};
I think that the best interpretation of the current text is that this is
an HFA, because there is only one entry in the "Fundamental Data Types"
table, which is the only thing considered in the definition of a
Homogeneous Aggregate.
However, the table in the "Mapping of C & C++ built-in data types"
section used the formats in a column which otherwise contains
Fundamental Data Types, which could be read to imply that the above
struct is _not_ an HFA. I don't think this is correct, so I've moved the
formats to the notes column, making it clear that the two source types
map to the same Fundamental Data Type.
Current compiler behaviour:
* Clang considers this struct to be an HFA, matches the behaviour
described in this ABI patch.
* GCC does not consider it to be an HFA, but it also does not think that
a struct only containing __bf16 is an HFA either. That's unambiguously
incorrect both before and after this patch, so it's just a special
case of a broader GCC bug.
smithp35
approved these changes
Mar 11, 2025
Contributor
smithp35
left a comment
There was a problem hiding this comment.
LGTM.
I think this is the best option given the existing text. While it does seem strange to consider a mix of __fp16 and __bf16 as homogenous, in terms of making good use of the registers in the calling convention it makes sense.
Would like to see if there are any objections on the GNU side?
Contributor
|
Agreed to merge this PR with Arm's GNU team. While it is not ideal to have __bf16 and __fp16 mapping to the same underlying natural type, changing it risks breaking too much existing code. |
Contributor
|
For the record, I've filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120007 to track this on the GCC side. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, it's not completely clear whether a struct containing a mixture of different 16-bit floating point types is a Homogeneous Aggregate or not:
struct foo {
__fp16 a;
__bf16 b;
};
I think that the best interpretation of the current text is that this is an HFA, because there is only one entry in the "Fundamental Data Types" table, which is the only thing considered in the definition of a Homogeneous Aggregate.
However, the table in the "Mapping of C & C++ built-in data types" section used the formats in a column which otherwise contains Fundamental Data Types, which could be read to imply that the above struct is not an HFA. I don't think this is correct, so I've moved the formats to the notes column, making it clear that the two source types map to the same Fundamental Data Type.
Current compiler behaviour: