-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang][x86]: allow PCLMULQDQ intrinsics to be used in constexpr #169214
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
Open
ahmednoursphinx
wants to merge
14
commits into
llvm:main
Choose a base branch
from
ahmednoursphinx:issue_168741
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
60fac68
[Clang][x86]: allow PCLMULQDQ intrinsics to be used in constexpr
ahmednoursphinx 12b605b
chore: Format files
ahmednoursphinx 2f80098
refactor: PR Feedback
ahmednoursphinx e3de251
refactor: simplify conversion from APSInt to APInt
ahmednoursphinx 5afa1b1
refactor: Use static casting
ahmednoursphinx f5c5f23
refactor: update tests
ahmednoursphinx 0cee75e
Update InterpBuiltin.cpp
ahmednoursphinx 974ddac
Update ExprConstant.cpp
ahmednoursphinx 7a28323
refactor: Use APInt instead of APSInt
ahmednoursphinx 5c7eb8e
feat: update formatting
ahmednoursphinx 3a72489
feat: Use APIntOps::clmul
ahmednoursphinx 5c486a9
chore: format files
ahmednoursphinx ec1331c
refactor: remove unused conversion
ahmednoursphinx 931bcc5
feat: add upper bits testing
ahmednoursphinx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,42 @@ | ||
| // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +pclmul -emit-llvm -o - | FileCheck %s | ||
|
|
||
| // RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +pclmul -emit-llvm -o - -std=c++11 | FileCheck %s | ||
| // RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +pclmul -emit-llvm -o - -std=c++11 -fexperimental-new-constant-interpreter | FileCheck %s | ||
|
|
||
| #include <wmmintrin.h> | ||
| #include "builtin_test_helpers.h" | ||
|
|
||
| __m128i test_mm_clmulepi64_si128(__m128i a, __m128i b) { | ||
| // CHECK: @llvm.x86.pclmulqdq | ||
| return _mm_clmulepi64_si128(a, b, 0); | ||
| } | ||
|
|
||
| // Test constexpr evaluation for _mm_clmulepi64_si128 | ||
| // imm8=0x00: lower 64 bits of both operands | ||
| // Test case: 0x1 * 0x3 = 0x3 (carry-less multiplication) | ||
| TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x1ULL, 0x0ULL}), ((__m128i){0x3ULL, 0x0ULL}), 0x00), 0x3ULL, 0x0ULL)); | ||
|
|
||
| // imm8=0x01: upper 64 bits of first operand, lower 64 bits of second | ||
| TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x0ULL, 0x1ULL}), ((__m128i){0x3ULL, 0x0ULL}), 0x01), 0x3ULL, 0x0ULL)); | ||
|
|
||
| // imm8=0x10: lower 64 bits of first operand, upper 64 bits of second | ||
| TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x1ULL, 0x0ULL}), ((__m128i){0x0ULL, 0x3ULL}), 0x10), 0x3ULL, 0x0ULL)); | ||
|
|
||
| // imm8=0x11: upper 64 bits of both operands | ||
| TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x0ULL, 0x1ULL}), ((__m128i){0x0ULL, 0x3ULL}), 0x11), 0x3ULL, 0x0ULL)); | ||
|
|
||
| // Test cases with non-zero upper 64-bit results | ||
| // imm8=0x00: lower 64 bits of both operands | ||
| // 0x8000000000000000 * 0x2 = result with upper bits set | ||
| TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){(long long)0x8000000000000000ULL, 0x0ULL}), ((__m128i){0x2ULL, 0x0ULL}), 0x00), 0x0ULL, 0x1ULL)); | ||
|
|
||
| // imm8=0x01: upper 64 bits of first operand, lower 64 bits of second | ||
| // 0xFFFFFFFFFFFFFFFF * 0x2 = result with upper bits set | ||
| TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x0ULL, (long long)0xFFFFFFFFFFFFFFFFULL}), ((__m128i){0x2ULL, 0x0ULL}), 0x01), 0xFFFFFFFFFFFFFFFEULL, 0x1ULL)); | ||
|
|
||
| // imm8=0x10: lower 64 bits of first operand, upper 64 bits of second | ||
| // 0x1000000000000000 * 0x10 = result with upper bits set | ||
| TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){(long long)0x1000000000000000ULL, 0x0ULL}), ((__m128i){0x0ULL, 0x10ULL}), 0x10), 0x0ULL, 0x1ULL)); | ||
|
|
||
| // imm8=0x11: upper 64 bits of both operands | ||
| // 0x8000000000000001 * 0x8000000000000001 = result with upper bits set | ||
| TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x0ULL, (long long)0x8000000000000001ULL}), ((__m128i){0x0ULL, (long long)0x8000000000000001ULL}), 0x11), 0x1ULL, 0x4000000000000000ULL)); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,30 @@ | ||
| // RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +vpclmulqdq -emit-llvm -o - | FileCheck %s --check-prefix AVX | ||
| // RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +vpclmulqdq -target-feature +avx512f -emit-llvm -o - | FileCheck %s --check-prefixes AVX,AVX512 | ||
| // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +vpclmulqdq -emit-llvm -o - -std=c++11 | FileCheck %s --check-prefix AVX | ||
| // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +vpclmulqdq -target-feature +avx512f -emit-llvm -o - -std=c++11 | FileCheck %s --check-prefixes AVX,AVX512 | ||
| // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +vpclmulqdq -emit-llvm -o - -std=c++11 -fexperimental-new-constant-interpreter | FileCheck %s --check-prefix AVX | ||
| // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +vpclmulqdq -target-feature +avx512f -emit-llvm -o - -std=c++11 -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes AVX,AVX512 | ||
|
|
||
| #include <immintrin.h> | ||
| #include "builtin_test_helpers.h" | ||
|
|
||
| __m256i test_mm256_clmulepi64_epi128(__m256i A, __m256i B) { | ||
| // AVX: @llvm.x86.pclmulqdq.256 | ||
| return _mm256_clmulepi64_epi128(A, B, 0); | ||
| } | ||
|
|
||
| // Test constexpr evaluation for _mm256_clmulepi64_epi128 | ||
| // Each 128-bit lane is processed independently | ||
| TEST_CONSTEXPR(match_m256i(_mm256_clmulepi64_epi128(((__m256i){0x1ULL, 0x0ULL, 0x2ULL, 0x0ULL}), ((__m256i){0x3ULL, 0x0ULL, 0x5ULL, 0x0ULL}), 0x00), 0x3ULL, 0x0ULL, 0xaULL, 0x0ULL)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to see some complex values - not just some simple cases - we need to be certain that the implementation is complete - have you done any fuzz testing comparing constexpr vs runtime ? |
||
|
|
||
| #ifdef __AVX512F__ | ||
| __m512i test_mm512_clmulepi64_epi128(__m512i A, __m512i B) { | ||
| // AVX512: @llvm.x86.pclmulqdq.512 | ||
| return _mm512_clmulepi64_epi128(A, B, 0); | ||
| } | ||
|
|
||
| // Test constexpr evaluation for _mm512_clmulepi64_epi128 | ||
| // Each 128-bit lane is processed independently | ||
| TEST_CONSTEXPR(match_m512i(_mm512_clmulepi64_epi128(((__m512i){0x1ULL, 0x0ULL, 0x2ULL, 0x0ULL, 0x4ULL, 0x0ULL, 0x8ULL, 0x0ULL}), ((__m512i){0x3ULL, 0x0ULL, 0x5ULL, 0x0ULL, 0x7ULL, 0x0ULL, 0x9ULL, 0x0ULL}), 0x00), 0x3ULL, 0x0ULL, 0xaULL, 0x0ULL, 0x1cULL, 0x0ULL, 0x48ULL, 0x0ULL)); | ||
| #endif | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we need tests showing results in the upper 64-bits as well:
https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=clmul&ig_expand=754