Skip to content

Commit

Permalink
[RISCV][BF16] Enable __bf16 for riscv targets
Browse files Browse the repository at this point in the history
The RISC-V psABI recently added __bf16 in riscv-non-isa/riscv-elf-psabi-doc#367.
Now we can enable this new type in clang.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D150929
  • Loading branch information
joshua-arch1 committed Aug 1, 2023
1 parent 93a3706 commit a5791bf
Show file tree
Hide file tree
Showing 5 changed files with 612 additions and 7 deletions.
1 change: 1 addition & 0 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ to ``float``; see below for more information on this emulation.
* ``__bf16`` is supported on the following targets (currently never natively):
* 32-bit ARM
* 64-bit ARM (AArch64)
* RISC-V
* X86 (when SSE2 is available)

(For X86, SSE2 is available on 64-bit and all recent 32-bit processors.)
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Basic/Targets/RISCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class RISCVTargetInfo : public TargetInfo {
public:
RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
: TargetInfo(Triple) {
BFloat16Width = 16;
BFloat16Align = 16;
BFloat16Format = &llvm::APFloat::BFloat();
LongDoubleWidth = 128;
LongDoubleAlign = 128;
LongDoubleFormat = &llvm::APFloat::IEEEquad();
Expand Down Expand Up @@ -101,6 +104,8 @@ class RISCVTargetInfo : public TargetInfo {

bool hasBitIntType() const override { return true; }

bool hasBFloat16Type() const override { return true; }

bool useFP16ConversionIntrinsics() const override {
return false;
}
Expand Down

0 comments on commit a5791bf

Please sign in to comment.