This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] implement <experimental/simd> casts.
Needs ReviewPublic

Authored by timshen on Dec 19 2017, 2:47 PM.

Details

Summary

Casts are implemented in terms of static_casts and loops.

Event Timeline

timshen created this revision.Dec 19 2017, 2:47 PM
timshen updated this revision to Diff 127639.Dec 19 2017, 5:49 PM

s/_LIBCPP_HAS_VECTOR_EXTENSION/_LIBCPP_HAS_NO_VECTOR_EXTENSION/

timshen updated this revision to Diff 129010.Jan 8 2018, 4:58 PM

Rebased.

timshen edited the summary of this revision. (Show Details)Apr 5 2018, 11:46 AM

In general, this looks good to me.
I suggested a lot of test improvements, but not very much to the code.
Needs the same kind of namespace changes in the tests as in D41376, but that's a minor thing.

libcxx/include/experimental/simd
1068

Weird indentation in the enable_if

libcxx/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp
19

All the tests should #include "test_macros.h"

22

I think this is worth a comment here - "This conversion is deleted so that it prevents ..."

libcxx/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp
33

General comment: We have a macro called ASSERT_SAME_TYPE that makes this clearer.

Instead of all this, you can just write:

ASSERT_SAME_TYPE(decltype(static_simd_cast<simd<float, simd_abi::scalar>>(fixed_size_simd<int, 1>())), simd<float, simd_abi::scalar);
libcxx/test/std/experimental/simd/simd.casts/to_compatible.pass.cpp
39

Since this is an extension, then the test needs to live in test/libcxx, not test/std.
(and should probably be two tests, one in test/std, and one in test/libcxx).

Same for to_native.pass.cpp below.

libcxx/test/std/experimental/simd/simd.casts/to_fixed_size.pass.cpp
30

All of these tests need to check the "noexcept-ness" of the operation.
Fortunately, we have a macro for that, too:

ASSERT_NOEXCEPT (         to_fixed_size(std::declval<native_simd<int>>()));
ASSERT_SAME_TYPE(decltype(to_fixed_size(std::declval<native_simd<int>>())), fixed_size_simd<int, native_simd<int>::size()>);