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 to any discussions 
would be appreciated.

Regards,
Paul



From 0e2ceddffed88dab9cc459f7efcab2e36e1cb7e3 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_TIES_TO_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..b194659ae06 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_TIES_TO_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