# GSoC 2025: Bfloat16 in LLVM libc

DevFeed: [GSoC 2025: Bfloat16 in LLVM libc](<https://devfeed.tech/articles/gsoc-2025-bfloat16-in-llvm-libc-43123.md>)

Original publisher: [Read original article](<https://blog.llvm.org/posts/2025-09-10-bfloat16-in-llvm-libc/>)

Author: Krishna Pandey

Published: 2025-09-29T00:00:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [floating-point](<https://devfeed.tech/topics/floating-point.md>), [Hardware](<https://devfeed.tech/topics/hardware.md>), [Jule](<https://devfeed.tech/topics/jule.md>)

Tags: [2025](<https://devfeed.tech/tags/2025.md>), [arm](<https://devfeed.tech/tags/arm.md>), [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [floating-point](<https://devfeed.tech/tags/floating-point.md>), [gsoc](<https://devfeed.tech/tags/gsoc.md>), [hardware](<https://devfeed.tech/tags/hardware.md>), [libc](<https://devfeed.tech/tags/libc.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [math](<https://devfeed.tech/tags/math.md>), [risc-v](<https://devfeed.tech/tags/risc-v.md>), [x86](<https://devfeed.tech/tags/x86.md>)

## AI overview

This article describes a GSoC project that added BFloat16 support to LLVM libc. It covers the type, generic correctly rounded math functions, supported architectures, additional comparison and higher math functions, limitations, and planned work.

## Source excerpt

Introduction BFloat16 is a 16-bit floating-point format, introduced by Google and standardized in C++23 as std::bfloat16_t. It uses 1 sign bit, 8 exponent bits (the same as float), and 7 mantissa bits. This configuration allows BFloat16 to represent a much wider dynamic range than IEEE binary16 (~3x10^38 values compared to 65,504), though with lower precision. BFloat16 has become popular in AI and machine learning use-cases where it offers significant performance advantages over IEEE binary32 while preserving its approximate dynamic range. The goal of this project was to implement the BFloat16 type in LLVM libc along with the basic math functions like fabsbf16, fmaxbf16, etc. We also want all functions to be generic (platform-independent) and correctly rounded for all rounding modes. What was done BFloat16 type was added to LLVM libc (libc/src/__support/FPUtil/bfloat16.h) #144463. All 70 expected basic math functions for bfloat16 were implemented, using a generic approach that supports all libc supported architectures (ARM, RISC-V, GPUs, x86, Darwin) (see table below). Implemented two additional basic math functions: iscanonicalbf16 and issignalingbf16. Implemented higher math functions: sqrtbf16 #156654 and log_bf16 #157811 (open). Comparison operations for the FPBits class were added #144983. Basic Math FunctionPRfabsbf16#148398ceilbf16, floorbf16, roundbf16, roundevenbf16, truncbf16#152352bf16add, bf16addf, bf16addl, bf16addf128, bf16sub, bf16subf, bf16subl, bf16subf128#152774fmaxbf16, fminbf16#152782bf16mul, bf16mulf, bf16mull, bf16mulf128#152847fmaximumbf16, fmaximum_magbf16, fmaximum_mag_numbf16, fmaximum_numbf16, fminimumbf16, fminimum_magbf16, fminimum_mag_numbf16, fminimum_numbf16#152881bf16div, bf16divf, bf16divl, bf16divf128#153191bf16fma, bf16fmaf, bf16fmal, bf16fmaf128#153231llrintbf16, llroundbf16, lrintbf16, lroundbf16, nearbyintbf16, rintbf16#153882fromfpbf16, fromfpxbf16, ufromfpbf16, ufromfpxbf16#153992nextafterbf16, nextdownbf16, nexttowardbf16, n