# GSoC 2024: Half-precision in LLVM libc

DevFeed: [GSoC 2024: Half-precision in LLVM libc](<https://devfeed.tech/articles/gsoc-2024-half-precision-in-llvm-libc-43105.md>)

Original publisher: [Read original article](<https://blog.llvm.org/posts/2024-08-31-half-precision-in-llvm-libc/>)

Author: Nicolas Celik

Published: 2024-08-31T00: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>), [C](<https://devfeed.tech/topics/c.md>), [floating-point](<https://devfeed.tech/topics/floating-point.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [Mathematics](<https://devfeed.tech/topics/mathematics.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [standard](<https://devfeed.tech/topics/standard.md>)

Tags: [architectures](<https://devfeed.tech/tags/architectures.md>), [arm](<https://devfeed.tech/tags/arm.md>), [c](<https://devfeed.tech/tags/c.md>), [clang](<https://devfeed.tech/tags/clang.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [floating-point](<https://devfeed.tech/tags/floating-point.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [gsoc](<https://devfeed.tech/tags/gsoc.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [libc](<https://devfeed.tech/tags/libc.md>), [linux](<https://devfeed.tech/tags/linux.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [math](<https://devfeed.tech/tags/math.md>), [precision](<https://devfeed.tech/tags/precision.md>), [risc-v](<https://devfeed.tech/tags/risc-v.md>), [standard](<https://devfeed.tech/tags/standard.md>)

## AI overview

This article reports on a Google Summer of Code project that implemented C23 half-precision floating-point math functions in LLVM libc. It covers generated headers, generic and architecture-specific implementations, optimization work, merged operations, open pull requests, and compatibility issues across compilers, runtimes, CPUs, and architectures.

## Source excerpt

C23 defines new floating-point types, such as _Float16, which corresponds tothe binary16 format from IEEE Std 754, also known as "half-precision," or FP16.C23 also defines new variants of the C standard library's math functionsaccordingly, such as fabsf16 to get the absolute value of a _Float16. The "Half-precision in LLVM libc" Google Summer of Code 2024 project aimed toimplement these new _Float16 math functions in LLVM libc, making it the firstknown C standard library implementation to implement these C23 functions. We split math functions into two categories: basic operations and higher mathfunctions. The current implementation status of math functions in LLVM libc canbe viewed at https://libc.llvm.org/math/index.html#implementation-status. The exact goals of this project were to: Setup generated headers properly so that the _Float16 type and _Float16functions can be used with various compilers and architectures. Add generic implementations of _Float16 basic operations for supportedarchitectures. Add optimized implementations of _Float16 basic operations for specificarchitectures using special hardware instructions and compiler builtinswhenever possible. Add generic implementations of as many _Float16 higher math functions aspossible. We knew we would not have enough time to implement all of them. Work done The _Float16 type can now be used in generated headers, and declarations of_Float16 math functions are generated with #ifdef guards to enable themwhen they are supported. https://github.com/llvm/llvm-project/pull/93567 All 70 planned _Float16 basic operations have been merged. https://github.com/llvm/llvm-project/issues/93566 The _Float16, float and double variants of various basic operationshave been optimized on certain architectures. https://github.com/llvm/llvm-project/pull/98376 https://github.com/llvm/llvm-project/pull/99037 https://github.com/llvm/llvm-project/pull/100002 Out of the 54 planned _Float16 higher math functions, 8 have been mergedand 9 hav