-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Add _MM_FROUND_TO_NEAREST_TIES_EVEN to avx512fintrin.h #99691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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 commit adds a suitable macro definition.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-x86 Author: hpkfft.com (hpkfft) ChangesIntrinsics such as Full diff: https://github.com/llvm/llvm-project/pull/99691.diff 1 Files Affected:
diff --git a/clang/lib/Headers/avx512fintrin.h b/clang/lib/Headers/avx512fintrin.h
index 4f172c74b31cb..2d7b5c534e554 100644
--- a/clang/lib/Headers/avx512fintrin.h
+++ b/clang/lib/Headers/avx512fintrin.h
@@ -43,6 +43,7 @@ typedef unsigned short __mmask16;
/* 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
|
Note that IEEE Std 754-2019 for floating-point arithmetic specifies two rounding direction attributes to nearest: This patch follows that naming precedent by assuming round-to-nearest is understood. If there is a consensus to use a longer macro name (such as |
What's the ties mean here? The SDM uses |
I understand that the details of floating point arithmetic are somewhat of a specialized area of computer science. I suggest that this obligates a greater duty to show care and diligence, and so I thank you for not dismissing my concerns as too trivial to be worth discussing. Rounding is necessary when the infinitely precise mathematical result of a floating point computation is not representable as a floating point number in the specified format (e.g., single precision). Let's ignore directed rounding ( Hardware correctly implements the IEEE rounding attribute Note that some few instructions, e.g., I have written to the GCC mailing list to inquire as to whether they will accept this additional macro definition. Regards, |
Thanks @hpkfft for the thorough explanation. I'm fine with either |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the tests for m512_maskz_cvt_roundepu64_ps
e.t.c (in avx512dq-builtins.c )?
I happened to find this document from Intel https://www.intel.com/content/www/us/en/content-details/669773/intel-avx-512-fp16-instruction-set-for-intel-xeon-processor-based-products-technology-guide.html that contains this text "The C intrinsic constant selector name _MM_FROUND_TO_NEAREST_INT is not ideal, but that name has been historically used for so long in all common compilers that it is difficult to change to something more meaningful." |
I disagree, of course, that it's difficult to change. One need only merge this PR. I don't see a reason not to do so. Yes, I plan to update the tests if this PR is merged. I'll make that a separate PR. (It looks to be about 100 lines in the GCC code base and fewer here. I consider that an easy change, but there's no point in my doing the work if this PR is rejected.) |
Former dev for the math libraries of the Intel compiler here. It is true that the name _MM_FROUND_TO_NEAREST_INT is quite old. For instance (since I see an Intel document quoted here for which I may or may not have been one of the authors, and that "all common compilers" is typical codeword for MSVC or GCC), this name has been sleeping in GCC inside config/i386/smmintrin.h for 17 years now --- a file, like many before and since, that was added by an Intel colleague, H.J. Lu, in GCC. However, even back then, this was seen as a problematic name in the microscopic world of computational arithmetic (which is called Numerics at Intel), since, indeed, it does not round to an integer. Given that's the default rounding mode, that name did not leave the greatest impression. At least it's _MM_ROUND_NEAREST in xmmintrin.h, but that was a few years earlier. This commit does not change the existing name, it only adds a much less confusing one while respecting the nomenclature pattern. It will give the name that should have been, and it will help remove some confusion about what round to nearest actually is. |
Note that the following in xmmintrin.h
sets different bits than the |
How can we get MSVC to add the new name too? |
Regarding the Intel compiler, which is (unlike the LLVM project but like MSVC) proprietary, all such modifications are (by far) prompted by customer requests. These requests are communicated either directly to the engineers (for example, the Argonne National Laboratory makes all sorts of requests to MKL directly) or indirectly via tickets opened by the team who handles customers. Assuming that the process is similar at Microsoft, then you would need a (significant) customer of MSVC to contact them regarding adding the name. Now, it is possible that features found in open-source projects end up being ported in MSVC. All it needs is for a (significant) customer of MSVC to request it, because for some reason this is something they saw in GCC/LLVM/etc and they want it in MSVC. But before that happens, it needs a precedent; if the name is never put anywhere, then nobody will ever request it in MSVC. |
Aren't the latest versions of Intel's compiler, |
Correct. However, the libraries (e.g. math libraries) were all ported from |
GCC thread (for reference): https://gcc.gnu.org/pipermail/gcc-patches/2024-July/657957.html |
I see that both phoebewang and KanRobert work for Intel, so Intel's LLVM compiler Regarding the use of
Yes, it will take some time for this change to percolate though to other code bases and documents. But as in the proverb:
|
I'm good with adding the macro. But how it propagates to other compilers would be an chicken or the egg problem. User won't use this flag if they care the portability, while other compilers may be reluctant to add it if no requiest from their user. |
To be fair, regarding MSVC, it might be more than just a chicken and the egg problem. It is sometimes in the best interests of Microsoft to make it as painful as possible for their customers to port their code onto other platforms, or to use standard libraries which are not implemented by Microsoft. On the other hand, when it comes to the rounding modes (for other functions than the intrinsics of this PR), MSVC has non-standard functions found nowhere else (e.g. _controlfp) which are using more objectionable names (_RC_CHOP for round toward zero... instead of a more natural name like _RC_ZERO). Outside the Microsoft ecosystem, code portability is usually less of an issue. There is also less of a need to twist the hand of a patron to get the owner of a proprietary compiler to fix something. |
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 commit adds a suitable macro definition.