Page MenuHomePhabricator

[X86][SSE] Enable constexpr on some basic SSE intrinsics (RFC)
Changes PlannedPublic

Authored by RKSimon on Dec 20 2020, 7:43 AM.

Details

Summary

This is an initial exploratory patch towards making some (basic initialization and arithmetic) SSE/AVX intrinsics usable in constant expressions.

I've only touched the SSE1 intrinsics that we can do so far - if people are happy with the approach I'll extend the patch to cover the equivalent SSE2->AVX512 intrinsics/types.

My main concern is how best to test these - all we're doing so far is checking that they will compile, which might be enough for now?

A later patch will have to address how to support builtin_shufflevector/builtin_convertvector and element accessors.

Diff Detail

Event Timeline

RKSimon requested review of this revision.Dec 20 2020, 7:43 AM
RKSimon created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 20 2020, 7:43 AM
RKSimon updated this revision to Diff 312979.Dec 20 2020, 7:44 AM

missing newline

RKSimon added a comment.EditedDec 20 2020, 9:04 AM

@tschuett could you explain a little more about how you see this working for vectors? Are you suggesting we embed the vector ops into static_assert ? The problem we have is how to extract a result from a comparison. I did wonder about bitcasting to a struct of some thing, but __builtin_bit_cast doesn't work for vectors, and I'm not sure what would be best.

tschuett added a comment.EditedDec 20 2020, 9:15 AM
constexpr bool test() {
float A = 1,0;
float B = 2,0;
float C = 3.0;
float D = 4,0;
__m128 AV;
__m128 BV;
__m128 result =  _mm_setr_ps(A, B, C, D);
result =  _mm_setzero_ps();
result = _mm_xor_ps(AV, BV);
return true;
}

int main() {
test();
static_assert(test());
return 0;
}

It should help you to test, whether you can call all functions in constant evaluation contexts and normal evaluations. I don't know whether you want to sprinkle some asserts into the test function.

RKSimon updated this revision to Diff 313038.Dec 21 2020, 1:53 AM

I've added the static_assert constexpr methods - this requires C++14 so I've left the existing constexpr wrapper tests with C++11 coverage as well.

Does anyone have any feedback before I expand this to cover all the SSE2/AVX equivalents?

pengfei added inline comments.Jan 4 2021, 6:22 AM
clang/test/CodeGen/X86/sse-builtins.c
815

What are these tests testing for?

RKSimon added inline comments.Jan 4 2021, 9:44 AM
clang/test/CodeGen/X86/sse-builtins.c
815

These are the more basic c++11 tests to ensure that the intrinsics can be used in a constexpr - without c++14 we can't actually create a __m128 type, so everything is on-the-fly.

The compiler _IS_ compiled with C++14, but the tests are not necessarily compiled as such. The Clang compiler still supports compiling all the way down to C++98.

RKSimon planned changes to this revision.Mar 29 2021, 3:54 AM