BrianLii opened a new pull request, #3310:
URL: https://github.com/apache/fory/pull/3310

   <!--
   **Thanks for contributing to Apache Fory™.**
   
   **If this is your first time opening a PR on fory, you can refer to 
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
   
   Contribution Checklist
   
       - The **Apache Fory™** community has requirements on the naming of pr 
titles. You can also find instructions in 
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
   
       - Apache Fory™ has a strong focus on performance. If the PR you submit 
will have an impact on performance, please benchmark it first and provide the 
benchmark result here.
   -->
   
   ## 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?
   
   <!--
   If any user-facing interface changes, please [open an 
issue](https://github.com/apache/fory/issues/new/choose) describing the need to 
do so and update the document if necessary.
   
   Delete section if not applicable.
   -->
   
   - [x] Does this PR introduce any public API change?
   - [x] Does this PR introduce any binary protocol compatibility change?
   
   ## Benchmark
   
   <!--
   When the PR has an impact on performance (if you don't know whether the PR 
will have an impact on performance, you can submit the PR first, and if it will 
have impact on performance, the code reviewer will explain it), be sure to 
attach a benchmark data here.
   
   Delete section if not applicable.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to