In response to feedback from LLVM/clang, I suggest naming the macro 
`_MM_FROUND_TO_NEAREST_TIES_EVEN`.
The updated patch is attached (and the previous one may be disregarded).


The clang PR is here: https://github.com/llvm/llvm-project/pull/99691

Regards,
Paul


-----Original message-----
From: Paul Caprioli
Sent: Saturday, July 20 2024, 12:01 pm
To: gcc-patches@gcc.gnu.org <gcc-patches@gcc.gnu.org>
Subject: [PATCH] i386: Add _MM_FROUND_TIES_TO_EVEN to smmintrin.h

Intrinsics such as `_mm512_add_round_ps` take a rounding mode argument to 
specify the floating point rounding mode. This and similar instructions do NOT 
round their result to an integer. Thus it is inappropriate for user code to 
specify the existing `_MM_FROUND_TO_NEAREST_INT` when desiring to round to the 
nearest floating point number. This patch adds a suitable macro definition.

Note that some few instructions, e.g., `ROUNDPS`, do round to an integer, so 
the existing macro definition ought not be deprecated.

Note that IEEE Std 754-2019 for floating-point arithmetic specifies two 
rounding direction attributes to nearest: `roundTiesToEven` and 
`roundTiesToAway`. Also, it specifies three directed rounding attributes: 
`roundTowardPositive`, `roundTowardNegative`, and `roundTowardZero`.

This patch follows that IEEE naming precedent.  As hardware correctly 
implements that IEEE rounding attribute, it seems best not to innovate in 
naming the macro....

Please note that I do not have write access to the git repo and that I am not a 
member of this email alias.  Your adding p...@hpkfft.com 
<mailto:p...@hpkfft.com> to any discussions would be appreciated.

Regards,
Paul

From ad12dbd202a8aa960dbbb5e23f8b990753d9ba7a Mon Sep 17 00:00:00 2001
From: Paul Caprioli <p...@hpkfft.com>
Date: Sat, 20 Jul 2024 11:31:06 -0700
Subject: [PATCH] Add _MM_FROUND_TO_NEAREST_TIES_EVEN to smmintrin.h

---
 gcc/config/i386/smmintrin.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/config/i386/smmintrin.h b/gcc/config/i386/smmintrin.h
index 4c315feec36..22ef9e966a7 100644
--- a/gcc/config/i386/smmintrin.h
+++ b/gcc/config/i386/smmintrin.h
@@ -39,6 +39,7 @@
 
 /* Rounding mode macros. */
 #define _MM_FROUND_TO_NEAREST_INT	0x00
+#define _MM_FROUND_TO_NEAREST_TIES_EVEN	0x00
 #define _MM_FROUND_TO_NEG_INF		0x01
 #define _MM_FROUND_TO_POS_INF		0x02
 #define _MM_FROUND_TO_ZERO		0x03
-- 
2.39.2

Reply via email to