[libclc] libclc: Use fma and simplify inf handling in half hypot (PR #211362)
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 22 12:54:32 PDT 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/211362
The inf handling should naturally fall through this sequence without
the explicit check.
>From 98aa28eea554ac1a297af1b3ee47fe4d1ce00638 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 22 Jul 2026 21:41:01 +0200
Subject: [PATCH] libclc: Use fma and simplify inf handling in half hypot
The inf handling should naturally fall through this sequence without
the explicit check.
---
libclc/clc/lib/generic/math/clc_hypot.cl | 1 +
libclc/clc/lib/generic/math/clc_hypot.inc | 6 ++----
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/libclc/clc/lib/generic/math/clc_hypot.cl b/libclc/clc/lib/generic/math/clc_hypot.cl
index b609d680fe7fb..bd9d0c0038d5f 100644
--- a/libclc/clc/lib/generic/math/clc_hypot.cl
+++ b/libclc/clc/lib/generic/math/clc_hypot.cl
@@ -10,6 +10,7 @@
#include "clc/float/definitions.h"
#include "clc/internal/clc.h"
#include "clc/math/clc_fabs.h"
+#include "clc/math/clc_fma.h"
#include "clc/math/clc_fmax.h"
#include "clc/math/clc_frexp_exp.h"
#include "clc/math/clc_ldexp.h"
diff --git a/libclc/clc/lib/generic/math/clc_hypot.inc b/libclc/clc/lib/generic/math/clc_hypot.inc
index 2321fb3dcbeb4..13fd908c9d088 100644
--- a/libclc/clc/lib/generic/math/clc_hypot.inc
+++ b/libclc/clc/lib/generic/math/clc_hypot.inc
@@ -47,11 +47,9 @@ _CLC_OVERLOAD _CLC_DEF _CLC_CONST __CLC_GENTYPE __clc_hypot(__CLC_GENTYPE x,
__CLC_GENTYPE y) {
__CLC_FLOATN fx = __CLC_CONVERT_FLOATN(x);
__CLC_FLOATN fy = __CLC_CONVERT_FLOATN(y);
- __CLC_FLOATN d2 = __clc_mad(fx, fx, fy * fy);
+ __CLC_FLOATN d2 = __clc_fma(fx, fx, fy * fy);
- __CLC_GENTYPE ret = __CLC_CONVERT_HALFN(__clc_sqrt_fast(d2));
-
- return __clc_isinf(x) || __clc_isinf(y) ? __CLC_GENTYPE_INF : ret;
+ return __CLC_CONVERT_HALFN(__clc_sqrt_fast(d2));
}
#endif
More information about the cfe-commits
mailing list