This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] <experimental/simd> Added internal storage type, constructors, subscript operators of class simd/simd_mask and related tests
ClosedPublic

Authored by Joy12138 on Feb 19 2023, 11:17 PM.

Details

Summary

[libcxx] <experimental/simd> Added internal storage type for class simd/simd_mask
[libcxx] <experimental/simd> Added all constructors of class simd/simd_mask and related tests
[libcxx] <experimental/simd> Added basic simd reference implementation, subscript operators of class simd/simd_mask and related tests

Diff Detail

Event Timeline

Joy12138 created this revision.Feb 19 2023, 11:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 19 2023, 11:17 PM
Herald added a subscriber: miyuki. · View Herald Transcript
Joy12138 requested review of this revision.Feb 19 2023, 11:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 19 2023, 11:17 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript

I mainly look quickly over the patch, can you get the patch to apply properly so the CI can test it?

libcxx/include/experimental/__simd/utility.h
52

Will the compiler optimize this?
Since a bool has two values it might otherwise be better to have a constexpr function to generate the result at compile time.

Mordante added inline comments.Feb 26 2023, 4:59 AM
libcxx/include/experimental/__simd/utility.h
30

This change needs to be done at other functions too.

44

Let's make sure unsupported sizes are ill-formed instead of triggering UB.

Joy12138 updated this revision to Diff 541398.Jul 18 2023, 2:04 AM

Rebase.

Due to the large amount of content in this section, I will split them into two patches to submit.

In this patch, we mainly implements the internal storage type of the simd/simd_mask class and the basic part of its auxiliary class reference.

In the next patch we will implement relevant user interfaces, including constructors and subscript access operators, as well as related tests.

The status paper will be updated in the next patch.

Joy12138 updated this revision to Diff 541399.Jul 18 2023, 2:07 AM
Joy12138 marked 2 inline comments as done.

Fix some comments

Joy12138 marked an inline comment as done.Jul 18 2023, 2:07 AM
Joy12138 updated this revision to Diff 541841.Jul 18 2023, 10:22 PM

Fix some CI errors

philnik requested changes to this revision.Jul 22 2023, 9:25 AM
philnik added a subscriber: philnik.
philnik added inline comments.
libcxx/include/experimental/__simd/reference.h
21

No need to call it out. If it's _Uglified it's library-internal.

21

__reference as a name is really generic.

47

It looks like you don't have any tests for the reference type currently. Please add some.

libcxx/include/experimental/__simd/scalar.h
30–31

Why make it so complicated? I'd just go for

// __get
return __data;

// __set
__data = __v;

Also, let's add a few _LIBCPP_ASSERT_UNCATEGORIZED (might need a rebase?) to make sure the index is never out of bounds.

39–40

That makes it a bit more obvious what you do when using it.

libcxx/include/experimental/__simd/utility.h
49
56–57

Isn't this just __v ? std::numeric_limits<_Up>::max() : 0?

libcxx/include/experimental/__simd/vec_ext.h
31–35

Why the conditional? Does this somehow help optimizations?

32

clang-tidy should actually complain here. I'll have to look into this.

43
libcxx/test/std/experimental/simd/test_utils.h
58–63

This isn't portable, and I don't really see the point. Nobody cares what the type is named internally.

This revision now requires changes to proceed.Jul 22 2023, 9:25 AM
Joy12138 updated this revision to Diff 543262.Jul 23 2023, 1:24 AM
Joy12138 marked 6 inline comments as done.

Rebase and fix some comments

Joy12138 added inline comments.Jul 23 2023, 7:14 PM
libcxx/include/experimental/__simd/vec_ext.h
31–35

libcxx CI - GCC 12 / C++latest gives errors with vector size that is not a power of two:

/home/libcxx-builder/.buildkite-agent/builds/google-libcxx-builder-8484195cd0ed-1/llvm-project/libcxx-ci/build/generic-gcc/include/c++/v1/experimental/__simd/vec_ext.h:30:7: error: number of vector components 3 not a power of two
   30 |   _Tp __data __attribute__((vector_size(sizeof(_Tp) * _Np)));
      |       ^~~~~~

It seems GCC 12 doesn't support non-power-of-two vector lengths. So I added the conditional.

libcxx/test/std/experimental/simd/test_utils.h
58–63

Then the type check of reference in the simd[_mask]_alias.pass.cpp is also unnecessary, right? Can I directly remove them?

philnik added inline comments.Jul 23 2023, 7:40 PM
libcxx/include/experimental/__simd/vec_ext.h
31–35

I would just always make it a power of two then. If there is no improvement when introducing the conditional, we can just remove it and make both compilers happy.

libcxx/test/std/experimental/simd/test_utils.h
58–63

Yes, they are unnecessary. You should add tests that check the properties of simd::reference and simd_mask::reference though.

Joy12138 updated this revision to Diff 543397.Jul 24 2023, 12:02 AM

Rebase and fix CI

Joy12138 updated this revision to Diff 543401.Jul 24 2023, 12:23 AM
Joy12138 marked 5 inline comments as done.

Fix some comments

Joy12138 updated this revision to Diff 543471.Jul 24 2023, 4:25 AM

Add test for reference alias

Joy12138 marked an inline comment as done.Jul 25 2023, 2:35 AM
philnik accepted this revision.Jul 27 2023, 9:05 PM

LGTM with the remaining comments addressed.

libcxx/include/experimental/__simd/reference.h
34

To avoid ADL you don't have to fully qualify the name.

libcxx/include/experimental/__simd/scalar.h
31

Note: Once the data is actually reachable, this should get a test.

libcxx/include/experimental/__simd/utility.h
54
This revision is now accepted and ready to land.Jul 27 2023, 9:05 PM
Joy12138 updated this revision to Diff 545344.Jul 29 2023, 1:21 AM
Joy12138 marked 3 inline comments as done.

Fix comments

It seems that the long double is a type with a size of 12 bytes on MinGW (DLL, i686). This conflicts with the current implementation. Vector extension requires the input parameter of vector size to be a power of 2 and a multiple of the size of the element type. 12 bytes cannot meet both requirements simultaneously. Should we temporarily exclude long double on MinGW (DLL, i686)? I think it would be more appropriate to add support for it when implement platform specialization optimization. @philnik

It seems that the long double is a type with a size of 12 bytes on MinGW (DLL, i686). This conflicts with the current implementation. Vector extension requires the input parameter of vector size to be a power of 2 and a multiple of the size of the element type. 12 bytes cannot meet both requirements simultaneously. Should we temporarily exclude long double on MinGW (DLL, i686)? I think it would be more appropriate to add support for it when implement platform specialization optimization. @philnik

Sounds fine to me with a TODO.

Joy12138 updated this revision to Diff 555963.Sep 5 2023, 9:47 PM

Excluded long double on MinGW (DLL, i686) temperarily

This revision was landed with ongoing or failed builds.Sep 11 2023, 8:42 PM
This revision was automatically updated to reflect the committed changes.