Skip to content

Conversation

SadiinsoSnowfall
Copy link
Contributor

@SadiinsoSnowfall SadiinsoSnowfall commented Sep 4, 2025

Change the definitions of _mm_setr_ph, _mm256_setr_ph and _mm512_setr_ph to be functions instead of macros.
Resolves #156709

Pending questions :

  • Should the _mm_setr_ph and _mm256_setr_ph functions be marked as __DEFAULT_FN_A TTRS128_CONSTEXPR and __DEFAULT_FN_ATTRS256_CONSTEXPR respectively ? I marked _mm512_setr_ph as __DEFAULT_FN_ATTRS512_CONSTEXPR because this attribute list is also applied to _mm512_set_ph. This is not the case for _mm_set_ph and _mm256_set_ph.
  • What about the other setr intrinsics such as _mm512_setr_ps, _mm512_setr_pd, _mm512_setr_epi64, etc... Should they be made into real functions too ? If so, should it be done in this PR ?

Copy link

github-actions bot commented Sep 4, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

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 permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

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.

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Sep 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Sadiinso (SadiinsoSnowfall)

Changes

Change the definitions of _mm_setr_ph, _mm256_setr_ph and _mm512_setr_ph to be functions instead of macros.
Resolves #156709

Pending questions :

  • Should the _mm_setr_ph and _mm256_setr_ph functions be marked as __DEFAULT_FN_A TTRS128_CONSTEXPR and __DEFAULT_FN_ATTRS256_CONSTEXPR respectively ? I marked _mm512_setr_ph as __DEFAULT_FN_ATTRS512_CONSTEXPR because this attribute list is also applied to _mm512_set_ph. This is not the case for _mm_set_ph and _mm256_set_ph.
  • What about the other setr intrinsics such as _mm512_setr_ps, _mm512_setr_pd, _mm512_setr_epi64, etc... Should they be made into real functions too ? If so, should it be done in this PR ?

Full diff: https://github.com/llvm/llvm-project/pull/156819.diff

2 Files Affected:

  • (modified) clang/lib/Headers/avx512fp16intrin.h (+14-7)
  • (modified) clang/lib/Headers/avx512vlfp16intrin.h (+13-6)
diff --git a/clang/lib/Headers/avx512fp16intrin.h b/clang/lib/Headers/avx512fp16intrin.h
index 25f65aee7ff11..f501974d34c97 100644
--- a/clang/lib/Headers/avx512fp16intrin.h
+++ b/clang/lib/Headers/avx512fp16intrin.h
@@ -100,13 +100,20 @@ _mm512_set_ph(_Float16 __h1, _Float16 __h2, _Float16 __h3, _Float16 __h4,
                             __h4,  __h3,  __h2,  __h1};
 }
 
-#define _mm512_setr_ph(h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, \
-                       h14, h15, h16, h17, h18, h19, h20, h21, h22, h23, h24,  \
-                       h25, h26, h27, h28, h29, h30, h31, h32)                 \
-  _mm512_set_ph((h32), (h31), (h30), (h29), (h28), (h27), (h26), (h25), (h24), \
-                (h23), (h22), (h21), (h20), (h19), (h18), (h17), (h16), (h15), \
-                (h14), (h13), (h12), (h11), (h10), (h9), (h8), (h7), (h6),     \
-                (h5), (h4), (h3), (h2), (h1))
+static __inline__ __m512h __DEFAULT_FN_ATTRS512_CONSTEXPR
+_mm512_setr_ph(_Float16 __h1, _Float16 __h2, _Float16 __h3, _Float16 __h4,
+               _Float16 __h5, _Float16 __h6, _Float16 __h7, _Float16 __h8,
+               _Float16 __h9, _Float16 __h10, _Float16 __h11, _Float16 __h12,
+               _Float16 __h13, _Float16 __h14, _Float16 __h15, _Float16 __h16,
+               _Float16 __h17, _Float16 __h18, _Float16 __h19, _Float16 __h20,
+               _Float16 __h21, _Float16 __h22, _Float16 __h23, _Float16 __h24,
+               _Float16 __h25, _Float16 __h26, _Float16 __h27, _Float16 __h28,
+               _Float16 __h29, _Float16 __h30, _Float16 __h31, _Float16 __h32) {
+  return _mm512_set_ph(__h32, __h31, __h30, __h29, __h28, __h27, __h26, __h25,
+                       __h24, __h23, __h22, __h21, __h20, __h19, __h18, __h17,
+                       __h16, __h15, __h14, __h13, __h12, __h11, __h10, __h9,
+                       __h8, __h7, __h6, __h5, __h4, __h3, __h2, __h1);
+}
 
 static __inline __m512h __DEFAULT_FN_ATTRS512
 _mm512_set1_pch(_Float16 _Complex __h) {
diff --git a/clang/lib/Headers/avx512vlfp16intrin.h b/clang/lib/Headers/avx512vlfp16intrin.h
index 98ad9b54eef39..a74e43170fc33 100644
--- a/clang/lib/Headers/avx512vlfp16intrin.h
+++ b/clang/lib/Headers/avx512vlfp16intrin.h
@@ -81,13 +81,20 @@ _mm256_set_ph(_Float16 __h1, _Float16 __h2, _Float16 __h3, _Float16 __h4,
                             __h4,  __h3,  __h2,  __h1};
 }
 
-#define _mm_setr_ph(h1, h2, h3, h4, h5, h6, h7, h8)                            \
-  _mm_set_ph((h8), (h7), (h6), (h5), (h4), (h3), (h2), (h1))
+static __inline__ __m128h __DEFAULT_FN_ATTRS128
+_mm_setr_ph(_Float16 __h1, _Float16 __h2, _Float16 __h3, _Float16 __h4,
+            _Float16 __h5, _Float16 __h6, _Float16 __h7, _Float16 __h8) {
+  return _mm_set_ph(__h8, __h7, __h6, __h5, __h4, __h3, __h2, __h1);
+}
 
-#define _mm256_setr_ph(h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, \
-                       h14, h15, h16)                                          \
-  _mm256_set_ph((h16), (h15), (h14), (h13), (h12), (h11), (h10), (h9), (h8),   \
-                (h7), (h6), (h5), (h4), (h3), (h2), (h1))
+static __inline__ __m256h __DEFAULT_FN_ATTRS256
+_mm256_setr_ph(_Float16 __h1, _Float16 __h2, _Float16 __h3, _Float16 __h4,
+               _Float16 __h5, _Float16 __h6, _Float16 __h7, _Float16 __h8,
+               _Float16 __h9, _Float16 __h10, _Float16 __h11, _Float16 __h12,
+               _Float16 __h13, _Float16 __h14, _Float16 __h15, _Float16 __h16) {
+  return _mm256_set_ph(__h16, __h15, __h14, __h13, __h12, __h11, __h10, __h9,
+                       __h8, __h7, __h6, __h5, __h4, __h3, __h2, __h1);
+}
 
 static __inline__ __m256h __DEFAULT_FN_ATTRS256 _mm256_add_ph(__m256h __A,
                                                               __m256h __B) {

@phoebewang
Copy link
Contributor

phoebewang commented Sep 4, 2025

Change the definitions of _mm_setr_ph, _mm256_setr_ph and _mm512_setr_ph to be functions instead of macros. Resolves #156709

Pending questions :

  • Should the _mm_setr_ph and _mm256_setr_ph functions be marked as __DEFAULT_FN_A TTRS128_CONSTEXPR and __DEFAULT_FN_ATTRS256_CONSTEXPR respectively ? I marked _mm512_setr_ph as __DEFAULT_FN_ATTRS512_CONSTEXPR because this attribute list is also applied to _mm512_set_ph. This is not the case for _mm_set_ph and _mm256_set_ph.

#152910 only solves _mm512_setr_ph. So leaving _mm_setr_ph and _mm256_setr_ph as is would be fine.

  • What about the other setr intrinsics such as _mm512_setr_ps, _mm512_setr_pd, _mm512_setr_epi64, etc... Should they be made into real functions too ? If so, should it be done in this PR ?

Yes, you can do it in the same PR.

@RKSimon RKSimon self-requested a review September 4, 2025 09:31
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the avx512vlfp16intrin.h _set_ intrinsics have been converted to constexpr yet so that is fine - I'll raise a separate bug about them - #156866

The other avx512f _setr_ and _setr4_ intrinsics do need converting to (constexpr) functions - if you are willing to do so in this patch that would be great.

@SadiinsoSnowfall
Copy link
Contributor Author

I made the suggested additions to my initial commit

@SadiinsoSnowfall SadiinsoSnowfall changed the title X86: make the setr_ph intrinsics functions X86: make the set/r/4 intrinsics macros into functions Sep 4, 2025
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - cheers

@RKSimon RKSimon changed the title X86: make the set/r/4 intrinsics macros into functions [X86] make the set/r/4 intrinsics macros into functions Sep 4, 2025
@RKSimon RKSimon enabled auto-merge (squash) September 4, 2025 13:15
@RKSimon RKSimon merged commit c6b6d85 into llvm:main Sep 4, 2025
9 checks passed
Copy link

github-actions bot commented Sep 4, 2025

@SadiinsoSnowfall Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[x86] immintrin _mm<size>_setr_ph weird behaviour when passed an expanded parameter pack
4 participants