-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][bytecode] Implement constexpr vector unary operators +, -, ~, ! #105996
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0e4c511
[Clang][Interp] Implement constexpr vector unary operators +, -, ~, !
yronglin 15dd97f
Format
yronglin d0a1b13
[Clang][Interp] Address review comments
yronglin 88a8e4f
[clang][bytecode] recovery commented out test
yronglin 789a7ee
[clang][bytecode] Merge UO_LNot integer and floating code path and ge…
yronglin 8c850df
[clang][bytecode] Refine implementation
yronglin 6ebbfec
Remove -Wno-uninitialized
yronglin 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// RUN: %clang_cc1 %s -triple x86_64-linux-gnu -std=c++14 -fsyntax-only -verify | ||
// RUN: %clang_cc1 %s -triple x86_64-linux-gnu -fexperimental-new-constant-interpreter -std=c++14 -fsyntax-only -verify | ||
|
||
using FourCharsVecSize __attribute__((vector_size(4))) = char; | ||
using FourIntsVecSize __attribute__((vector_size(16))) = int; | ||
using FourLongLongsVecSize __attribute__((vector_size(32))) = long long; | ||
using FourFloatsVecSize __attribute__((vector_size(16))) = float; | ||
using FourDoublesVecSize __attribute__((vector_size(32))) = double; | ||
using FourI128VecSize __attribute__((vector_size(64))) = __int128; | ||
|
||
using FourCharsExtVec __attribute__((ext_vector_type(4))) = char; | ||
using FourIntsExtVec __attribute__((ext_vector_type(4))) = int; | ||
using FourI128ExtVec __attribute__((ext_vector_type(4))) = __int128; | ||
|
||
// Only int vs float makes a difference here, so we only need to test 1 of each. | ||
// Test Char to make sure the mixed-nature of shifts around char is evident. | ||
void CharUsage() { | ||
constexpr auto H = FourCharsVecSize{-1, -1, 0, -1}; | ||
constexpr auto InvH = -H; | ||
static_assert(InvH[0] == 1 && InvH[1] == 1 && InvH[2] == 0 && InvH[3] == 1, ""); | ||
|
||
constexpr auto ae = ~FourCharsVecSize{1, 2, 10, 20}; | ||
static_assert(ae[0] == -2 && ae[1] == -3 && ae[2] == -11 && ae[3] == -21, ""); | ||
|
||
constexpr auto af = !FourCharsVecSize{0, 1, 8, -1}; | ||
static_assert(af[0] == -1 && af[1] == 0 && af[2] == 0 && af[3] == 0, ""); | ||
} | ||
|
||
void CharExtVecUsage() { | ||
constexpr auto H = FourCharsExtVec{-1, -1, 0, -1}; | ||
constexpr auto InvH = -H; | ||
static_assert(InvH[0] == 1 && InvH[1] == 1 && InvH[2] == 0 && InvH[3] == 1, ""); | ||
|
||
constexpr auto ae = ~FourCharsExtVec{1, 2, 10, 20}; | ||
static_assert(ae[0] == -2 && ae[1] == -3 && ae[2] == -11 && ae[3] == -21, ""); | ||
|
||
constexpr auto af = !FourCharsExtVec{0, 1, 8, -1}; | ||
static_assert(af[0] == -1 && af[1] == 0 && af[2] == 0 && af[3] == 0, ""); | ||
} | ||
|
||
void FloatUsage() { | ||
constexpr auto Y = FourFloatsVecSize{1.200000e+01, 1.700000e+01, -1.000000e+00, -1.000000e+00}; | ||
constexpr auto Z = -Y; | ||
static_assert(Z[0] == -1.200000e+01 && Z[1] == -1.700000e+01 && Z[2] == 1.000000e+00 && Z[3] == 1.000000e+00, ""); | ||
|
||
// Operator ~ is illegal on floats. | ||
constexpr auto ae = ~FourFloatsVecSize{0, 1, 8, -1}; // expected-error {{invalid argument type}} | ||
|
||
constexpr auto af = !FourFloatsVecSize{0, 1, 8, -1}; | ||
static_assert(af[0] == -1 && af[1] == 0 && af[2] == 0 && af[3] == 0, ""); | ||
} | ||
|
||
void FloatVecUsage() { | ||
constexpr auto Y = FourFloatsVecSize{1.200000e+01, 1.700000e+01, -1.000000e+00, -1.000000e+00}; | ||
constexpr auto Z = -Y; | ||
static_assert(Z[0] == -1.200000e+01 && Z[1] == -1.700000e+01 && Z[2] == 1.000000e+00 && Z[3] == 1.000000e+00, ""); | ||
|
||
// Operator ~ is illegal on floats. | ||
constexpr auto ae = ~FourFloatsVecSize{0, 1, 8, -1}; // expected-error {{invalid argument type}} | ||
|
||
constexpr auto af = !FourFloatsVecSize{0, 1, 8, -1}; | ||
static_assert(af[0] == -1 && af[1] == 0 && af[2] == 0 && af[3] == 0, ""); | ||
} | ||
|
||
void I128Usage() { | ||
// Operator ~ is illegal on floats, so no test for that. | ||
constexpr auto c = ~FourI128VecSize{1, 2, 10, 20}; | ||
static_assert(c[0] == -2 && c[1] == -3 && c[2] == -11 && c[3] == -21, ""); | ||
|
||
constexpr auto d = !FourI128VecSize{0, 1, 8, -1}; | ||
static_assert(d[0] == -1 && d[1] == 0 && d[2] == 0 && d[3] == 0, ""); | ||
} | ||
|
||
void I128VecUsage() { | ||
// Operator ~ is illegal on floats, so no test for that. | ||
constexpr auto c = ~FourI128ExtVec{1, 2, 10, 20}; | ||
static_assert(c[0] == -2 && c[1] == -3 && c[2] == -11 && c[3] == -21, ""); | ||
|
||
constexpr auto d = !FourI128ExtVec{0, 1, 8, -1}; | ||
static_assert(d[0] == -1 && d[1] == 0 && d[2] == 0 && d[3] == 0, ""); | ||
} | ||
|
||
using FourBoolsExtVec __attribute__((ext_vector_type(4))) = bool; | ||
void BoolVecUsage() { | ||
constexpr auto j = !FourBoolsExtVec{true, false, true, false}; | ||
static_assert(j[0] == false && j[1] == true && j[2] == false && j[3] == true, ""); | ||
|
||
constexpr auto k = ~FourBoolsExtVec{true, false, true, false}; | ||
static_assert(k[0] == false && k[1] == true && k[2] == false && k[3] == true, ""); | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.