Skip to content

Issue 3284 bfloat#3310

Open
BrianLii wants to merge 6 commits intoapache:mainfrom
BrianLii:issue-3284-bfloat
Open

Issue 3284 bfloat#3310
BrianLii wants to merge 6 commits intoapache:mainfrom
BrianLii:issue-3284-bfloat

Conversation

@BrianLii
Copy link

@BrianLii BrianLii commented Feb 9, 2026

Why?

We want to use bfloat16 (BF16) in FDL to reduce payload size while keeping a wide exponent range (common in ML/AI workflows). Fory currently lacks a BF16 primitive and optimized arrays. This PR adds full support for bfloat16 in the Fory Go runtime and codegen.

What does this PR do?

  1. Compiler:
    • Adds bfloat16 to the IR type system (PrimitiveKind).
    • Updates the Go generator to map bfloat16 to bfloat16.BFloat16 and handle imports.
    • Adds codegen tests for bfloat16.
  2. Go Runtime:
    • Adds a new package go/fory/bfloat16 with a strong type type BFloat16 uint16.
    • Implements IEEE 754 compliant conversions between float32 and bfloat16 (round-to-nearest, ties-to-even).
    • Handles special values: NaN, Inf, ±0 correctly.
  3. Serialization:
    • Implements optimized serializers for bfloat16, []bfloat16, and [N]bfloat16, mirroring the float16 implementation structure.
  4. Type System:
    • Updates TypeResolver to register BFloat16, []BFloat16, and [N]BFloat16 types.
    • Adds type resolution logic to distinguish BFloat16 from uint16 (since it's an alias type) for correct serializer selection.
  5. Tests: Adds comprehensive unit tests for conversions, rounding logic, serialization, and codegen.

Related issues

Fixes #3284

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

@BrianLii BrianLii marked this pull request as ready for review February 9, 2026 00:27
@BrianLii BrianLii requested a review from chaokunyang as a code owner February 9, 2026 00:27
@BrianLii BrianLii marked this pull request as draft February 9, 2026 00:28
@BrianLii BrianLii marked this pull request as ready for review February 9, 2026 00:36
@chaokunyang
Copy link
Collaborator

@BrianLii
Copy link
Author

BrianLii commented Feb 9, 2026

Please read https://github.com/apache/fory/blob/main/CONTRIBUTING.md#how-to-title-your-pr to update PR title

Thank you very much for the reference. I tried to update the title, but I did not see the edit option.
image

The edit option looks like this:

image

reference: This GitHub official tutorial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Go] add bfloat16 and bfloat16_array

2 participants