From 4084f6900e0566b03bde23c112f7b3a04b298842 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 30 Apr 2026 11:05:19 -0400 Subject: [PATCH] util/half: Add double_to_float16_ru/rd helpers Reviewed-by: Erik Faye-Lund Part-of: --- src/util/half_float.h | 12 ++++++++++++ src/util/tests/half_float_test.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/util/half_float.h b/src/util/half_float.h index 10797454fe9..3ed47981f43 100644 --- a/src/util/half_float.h +++ b/src/util/half_float.h @@ -223,6 +223,18 @@ _mesa_double_to_float16_rtz(double val) return _mesa_float_to_float16_rtz(_mesa_reduce_double_for_f16(val)); } +static inline uint16_t +_mesa_double_to_float16_ru(double val) +{ + return _mesa_float_to_float16_ru(_mesa_reduce_double_for_f16(val)); +} + +static inline uint16_t +_mesa_double_to_float16_rd(double val) +{ + return _mesa_float_to_float16_rd(_mesa_reduce_double_for_f16(val)); +} + #ifdef __cplusplus namespace mesa diff --git a/src/util/tests/half_float_test.cpp b/src/util/tests/half_float_test.cpp index 1469e95f2af..f34692f7e75 100644 --- a/src/util/tests/half_float_test.cpp +++ b/src/util/tests/half_float_test.cpp @@ -539,3 +539,13 @@ TEST(double_to_float16_rtz, rounding) { test_double_to_half_rounding(_mesa_double_to_float16_rtz, RTZ); } + +TEST(double_to_float16_ru, rounding) +{ + test_double_to_half_rounding(_mesa_double_to_float16_ru, RU); +} + +TEST(double_to_float16_rd, rounding) +{ + test_double_to_half_rounding(_mesa_double_to_float16_rd, RD); +}