-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang] Add __bf16
Type Support Macros With Literal Suffix Support
#134214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bassiounix
wants to merge
18
commits into
llvm:main
Choose a base branch
from
bassiounix:bf16-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
620bdbe
add `bf16`/`BF16` suffix support
bassiounix d55e0ca
add `__bf16` macros
bassiounix d0b9ecd
fix formatting
bassiounix 94244f4
chore(style): fix redundant style
bassiounix 5b25898
chore: reorder `PickFP` arguments
bassiounix 2c62638
fix(bf suffix): fix float literal suffix support
bassiounix 3abe5e7
chore(docs): add release notes for the macros and bfloat literal suffix
bassiounix 9e48a49
chore(test): add test for bfloat literal suffix support
bassiounix 2680e73
chore(test): add test for `__bf16`/`BFLT16` predefined macros
bassiounix 3b793b2
fix(TargetInfo): save state of the type format after copy
bassiounix ae0cf84
chore(style): fix code style
bassiounix 621d5a3
Update clang/lib/Lex/LiteralSupport.cpp
bassiounix f6a05c3
Update clang/lib/Lex/LiteralSupport.cpp
bassiounix c272219
Update clang/lib/Lex/LiteralSupport.cpp
bassiounix 33d9adb
remove reduntant checks
bassiounix 3cc63e9
add more bf16 literal suffix tests
bassiounix e88f537
remove redundant check
bassiounix 6a88507
Add tests for unsupported target
bassiounix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -triple x86_64 -DSUPPORTED %s | ||
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -triple armv7 %s | ||
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -triple armv7 -target-feature +bf16 -DSUPPORTED %s | ||
|
||
#ifdef SUPPORTED | ||
|
||
__bf16 a = 1.b; // expected-error{{invalid suffix 'b' on floating constant}} | ||
__bf16 b = 1.bf; // expected-error{{invalid suffix 'bf' on floating constant}} | ||
__bf16 c = 1.bf166; // expected-error{{invalid suffix 'bf166' on floating constant}} | ||
__bf16 d = 1.bf1; // expected-error{{invalid suffix 'bf1' on floating constant}} | ||
|
||
__bf16 e = 1.B; // expected-error{{invalid suffix 'B' on floating constant}} | ||
__bf16 f = 1.BF; // expected-error{{invalid suffix 'BF' on floating constant}} | ||
__bf16 g = 1.BF166; // expected-error{{invalid suffix 'BF166' on floating constant}} | ||
__bf16 h = 1.BF1; // expected-error{{invalid suffix 'BF1' on floating constant}} | ||
|
||
__bf16 i = 1.bf16; // expect-success | ||
__bf16 j = 1.BF16; // expect-success | ||
|
||
__bf16 k = 1B; // expected-error{{invalid digit 'B' in decimal constant}} | ||
__bf16 l = 1BF; // expected-error{{invalid digit 'B' in decimal constant}} | ||
__bf16 m = 1BF166; // expected-error{{invalid digit 'B' in decimal constant}} | ||
__bf16 n = 1BF1; // expected-error{{invalid digit 'B' in decimal constant}} | ||
|
||
__bf16 o = 1b; // expected-error{{invalid digit 'b' in decimal constant}} | ||
__bf16 p = 1bf; // expected-error{{invalid digit 'b' in decimal constant}} | ||
__bf16 q = 1bf166; // expected-error{{invalid digit 'b' in decimal constant}} | ||
__bf16 r = 1bf1; // expected-error{{invalid digit 'b' in decimal constant}} | ||
|
||
__bf16 s = 1bf16; // expected-error{{invalid digit 'b' in decimal constant}} | ||
__bf16 t = 1BF16; // expected-error{{invalid digit 'B' in decimal constant}} | ||
|
||
__bf16 u = 1.bf16F16; // expected-error{{invalid suffix 'bf16F16' on floating constant}} | ||
__bf16 v = 1.BF16f16; // expected-error{{invalid suffix 'BF16f16' on floating constant}} | ||
__bf16 w = 1.F16bf16; // expected-error{{invalid suffix 'F16bf16' on floating constant}} | ||
|
||
#endif | ||
|
||
#ifndef SUPPORTED | ||
|
||
__bf16 a = 1.b; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'b' on floating constant}} | ||
__bf16 b = 1.bf; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'bf' on floating constant}} | ||
__bf16 c = 1.bf166; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'bf166' on floating constant}} | ||
__bf16 d = 1.bf1; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'bf1' on floating constant}} | ||
|
||
__bf16 e = 1.B; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'B' on floating constant}} | ||
__bf16 f = 1.BF; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'BF' on floating constant}} | ||
__bf16 g = 1.BF166; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'BF166' on floating constant}} | ||
__bf16 h = 1.BF1; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'BF1' on floating constant}} | ||
|
||
__bf16 i = 1.bf16; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'bf16' on floating constant}} | ||
__bf16 j = 1.BF16; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'BF16' on floating constant}} | ||
|
||
__bf16 k = 1B; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'B' in decimal constant}} | ||
__bf16 l = 1BF; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'B' in decimal constant}} | ||
__bf16 m = 1BF166; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'B' in decimal constant}} | ||
__bf16 n = 1BF1; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'B' in decimal constant}} | ||
|
||
__bf16 o = 1b; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'b' in decimal constant}} | ||
__bf16 p = 1bf; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'b' in decimal constant}} | ||
__bf16 q = 1bf166; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'b' in decimal constant}} | ||
__bf16 r = 1bf1; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'b' in decimal constant}} | ||
|
||
__bf16 s = 1bf16; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'b' in decimal constant}} | ||
__bf16 t = 1BF16; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid digit 'B' in decimal constant}} | ||
|
||
__bf16 u = 1.bf16F16; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'bf16F16' on floating constant}} | ||
__bf16 v = 1.BF16f16; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'BF16f16' on floating constant}} | ||
__bf16 w = 1.F16bf16; // expected-error{{__bf16 is not supported on this target}} expected-error{{invalid suffix 'F16bf16' on floating constant}} | ||
|
||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// RUN: %clang_cc1 -E -dM -ffreestanding < /dev/null | FileCheck -match-full-lines -check-prefix BFLT16 %s | ||
|
||
// BFLT16: #define __BFLT16_DECIMAL_DIG__ 4 | ||
// BFLT16: #define __BFLT16_DENORM_MIN__ 9.18354961579912115600575419704879436e-41BF16 | ||
// BFLT16: #define __BFLT16_DIG__ 2 | ||
// BFLT16: #define __BFLT16_EPSILON__ 7.8125e-3BF16 | ||
// BFLT16: #define __BFLT16_HAS_DENORM__ 1 | ||
// BFLT16: #define __BFLT16_HAS_INFINITY__ 1 | ||
// BFLT16: #define __BFLT16_HAS_QUIET_NAN__ 1 | ||
// BFLT16: #define __BFLT16_MANT_DIG__ 8 | ||
// BFLT16: #define __BFLT16_MAX_10_EXP__ 38 | ||
// BFLT16: #define __BFLT16_MAX_EXP__ 128 | ||
// BFLT16: #define __BFLT16_MAX__ 3.38953138925153547590470800371487867e+38BF16 | ||
// BFLT16: #define __BFLT16_MIN_10_EXP__ (-37) | ||
// BFLT16: #define __BFLT16_MIN_EXP__ (-125) | ||
// BFLT16: #define __BFLT16_MIN__ 1.17549435082228750796873653722224568e-38BF16 | ||
// BFLT16: #define __BFLT16_NORM_MAX__ 3.38953138925153547590470800371487867e+38BF16 |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true for C++23. Do we want extension warnings in other language modes @AaronBallman?
As an aside, did anyone benchmark that the pattern we use in this function is actually faster than string_view
comparisons?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should have extension warnings in other language modes as well as the precompat warning for C++ before C++23.