[PATCH v2 03/13] math: Simplify f{max,min} template
Adhemerval Zanella
adhemerval.zanella@linaro.org
Fri Jan 23 13:02:16 GMT 2026
On x86_64, it allows the fast path (normal/subnormal inputs) to use maxsd.
With gcc-15 targetting x86_64 for fmax:
* master:
ucomisd xmm0, xmm1
jnb .L1
ucomisd xmm1, xmm0
ja .L13
[...]
.L13:
movapd xmm0, xmm1
.L1:
ret
* patch;
ucomisd xmm0, xmm1
jp .L2
maxsd xmm0, xmm1
ret
---
math/s_fmax_template.c | 6 ++----
math/s_fmin_template.c | 6 ++----
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/math/s_fmax_template.c b/math/s_fmax_template.c
index c3ac7d7548..5921d2b43c 100644
--- a/math/s_fmax_template.c
+++ b/math/s_fmax_template.c
@@ -24,10 +24,8 @@ M_DECL_FUNC (__fmax) (FLOAT x, FLOAT y)
#if M_USE_BUILTIN (FMAX)
return M_SUF (__builtin_fmax) (x, y);
#else
- if (isgreaterequal (x, y))
- return x;
- else if (isless (x, y))
- return y;
+ if (__glibc_likely (!isunordered (x, y)))
+ return x > y ? x : y;
else if (issignaling (x) || issignaling (y))
return x + y;
else
diff --git a/math/s_fmin_template.c b/math/s_fmin_template.c
index f3112a95f5..e78358c8ed 100644
--- a/math/s_fmin_template.c
+++ b/math/s_fmin_template.c
@@ -24,10 +24,8 @@ M_DECL_FUNC (__fmin) (FLOAT x, FLOAT y)
#if M_USE_BUILTIN (FMIN)
return M_SUF (__builtin_fmin) (x, y);
#else
- if (islessequal (x, y))
- return x;
- else if (isgreater (x, y))
- return y;
+ if (__glibc_likely (!isunordered (x, y)))
+ return x > y ? y : x;
else if (issignaling (x) || issignaling (y))
return x + y;
else
--
2.43.0
More information about the Libc-alpha
mailing list