Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

f16b Primitive Type

Metadata
Point of contactJames
StatusProposed
compiler championDavid Wood
lang championTyler Mandry
Teamscompiler, lang
Task owners(none)

Arm’s Rust team is David Wood, Adam Gemmell, Rémy Rakic and James. This goal will be primarily worked on by James

Summary

Implementation of a f16b type in core::num for the 16-bit Brain Floating Point format.

Motivation

A first-class f16b type for the is primarily useful for target-specific SIMD and Matrix APIs. It is also useful where memory bandwidth, storage size, and vector throughput matter more than decimal precision. The main use case is machine learning and AI workloads, where values are often stored or multiplied in f16b while accumulation happens in wider precision.

b16 is increasingly found in hardware across multiple architecutues such as AArch64 Neoverse N2, x86_64 Cooper Lake and RISC-V. All offering a level of native support for scalar and vector operations with discoverability through target-feature mechanisms.

The status quo

Presently bf16 is present through wrapper types over a u16 with adhoc lowering rules. Using a u16 preserves the raw bits, but it loses the meaning of the value. It also cannot use the usual floating-point surface of the language, such as casts, literals, constants, formatting, arithmetic traits, or generic bounds over floating-point types.

As such, workarounds are required to use a bf16 type today. rust-lang/rust#140763 is an example of the current workaround: it adds temporary codegen bypasses so Rust signatures using i16 / i16xN can call LLVM intrinsics whose real signatures use bf16 / bf16xN.

What we propose to do about it

We propose a f16b type in core::num that can be used across architectures for FFI and with target-specific intrinsics.

This goal does not propose to make it a general-purpose arithmetic type, so does not propose portable rust operations, portable library methods, etc.

Work items over the next year

TaskOwner(s)Notes
Draft RFCJamesbarford
Resolve feedback on the RFCJamesbarford
Approval for an experiement behind a !feature(f16b)Jamesbarford
Implement experimentJamesbarford
Stabilisation concernsJamesbarford
Write documentation, references and limitationsJamesbarford
StabiliseJamesbarford

Team asks

TeamSupport levelNotes
langMediumReview of RFC
compilerMediumPR Reviews, both of the RFC and of the subsequent implementation work

Funding

The f16b is being worked on by the Rust team at Arm and the goal owners have sufficient capacity to do the work.

Frequently asked questions

  • What does the b in f16b mean? The b stands for brain