Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libcxx] implement <experimental/simd> declarations based on P0214R7.
Summary: The patch includes all declarations, and also implements the following features: * ABI. * narrowing-conversion related SFIANE, including simd<> ctors and (static_)simd_cast. Reviewers: mclow.lists, EricWF Subscribers: lichray, sanjoy, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D41148 llvm-svn: 330627
- Loading branch information
Showing
14 changed files
with
1,956 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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,12 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <experimental/simd> | ||
|
||
int main() {} |
40 changes: 40 additions & 0 deletions
40
libcxx/test/std/experimental/simd/simd.casts/simd_cast.pass.cpp
This file contains 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,40 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++98, c++03 | ||
|
||
// <experimental/simd> | ||
// | ||
// [simd.casts] | ||
// template <class T, class U, class Abi> see below simd_cast(const simd<U, Abi>&); | ||
#include <experimental/simd> | ||
#include <cstdint> | ||
|
||
using namespace std::experimental::parallelism_v2; | ||
|
||
static_assert(std::is_same<decltype(simd_cast<int32_t>(native_simd<int32_t>())), | ||
native_simd<int32_t>>::value, | ||
""); | ||
|
||
static_assert( | ||
std::is_same<decltype(simd_cast<int64_t>(fixed_size_simd<int32_t, 4>())), | ||
fixed_size_simd<int64_t, 4>>::value, | ||
""); | ||
|
||
static_assert(std::is_same<decltype(simd_cast<fixed_size_simd<int64_t, 1>>( | ||
simd<int32_t, simd_abi::scalar>())), | ||
fixed_size_simd<int64_t, 1>>::value, | ||
""); | ||
|
||
static_assert(std::is_same<decltype(simd_cast<simd<int64_t, simd_abi::scalar>>( | ||
fixed_size_simd<int32_t, 1>())), | ||
simd<int64_t, simd_abi::scalar>>::value, | ||
""); | ||
|
||
int main() {} |
38 changes: 38 additions & 0 deletions
38
libcxx/test/std/experimental/simd/simd.casts/static_simd_cast.pass.cpp
This file contains 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,38 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++98, c++03 | ||
|
||
// <experimental/simd> | ||
// | ||
// [simd.casts] | ||
// template <class T, class U, class Abi> see below static_simd_cast(const simd<U, Abi>&); | ||
|
||
#include <experimental/simd> | ||
#include <cstdint> | ||
|
||
using namespace std::experimental::parallelism_v2; | ||
|
||
static_assert( | ||
std::is_same<decltype(static_simd_cast<float>(native_simd<int>())), | ||
native_simd<float>>::value, | ||
""); | ||
|
||
static_assert(std::is_same<decltype(static_simd_cast<fixed_size_simd<float, 1>>( | ||
simd<int, simd_abi::scalar>())), | ||
fixed_size_simd<float, 1>>::value, | ||
""); | ||
|
||
static_assert( | ||
std::is_same<decltype(static_simd_cast<simd<float, simd_abi::scalar>>( | ||
fixed_size_simd<int, 1>())), | ||
simd<float, simd_abi::scalar>>::value, | ||
""); | ||
|
||
int main() {} |
55 changes: 55 additions & 0 deletions
55
libcxx/test/std/experimental/simd/simd.cons/broadcast.pass.cpp
This file contains 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,55 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++98, c++03 | ||
|
||
// <experimental/simd> | ||
// | ||
// [simd.class] | ||
// template <class U> simd(U&& value); | ||
|
||
#include <cstdint> | ||
#include <experimental/simd> | ||
|
||
using namespace std::experimental::parallelism_v2; | ||
|
||
template <class T, class... Args> | ||
auto not_supported_native_simd_ctor(Args&&... args) | ||
-> decltype(native_simd<T>(std::forward<Args>(args)...), void()) = delete; | ||
|
||
template <class T> | ||
void not_supported_native_simd_ctor(...) {} | ||
|
||
template <class T, class... Args> | ||
auto supported_native_simd_ctor(Args&&... args) | ||
-> decltype(native_simd<T>(std::forward<Args>(args)...), void()) {} | ||
|
||
template <class T> | ||
void supported_native_simd_ctor(...) = delete; | ||
|
||
void compile_narrowing_conversion() { | ||
supported_native_simd_ctor<int8_t>(3); | ||
supported_native_simd_ctor<int16_t>(3); | ||
supported_native_simd_ctor<int32_t>(3); | ||
supported_native_simd_ctor<int64_t>(3); | ||
supported_native_simd_ctor<uint8_t>(3); | ||
supported_native_simd_ctor<uint16_t>(3); | ||
supported_native_simd_ctor<uint32_t>(3); | ||
supported_native_simd_ctor<uint64_t>(3); | ||
supported_native_simd_ctor<float>(3.f); | ||
supported_native_simd_ctor<double>(3.); | ||
supported_native_simd_ctor<long double>(3.); | ||
|
||
not_supported_native_simd_ctor<float>(3.); | ||
not_supported_native_simd_ctor<int8_t>(long(3)); | ||
not_supported_native_simd_ctor<float>(long(3)); | ||
not_supported_native_simd_ctor<int>(3.); | ||
} | ||
|
||
int main() {} |
43 changes: 43 additions & 0 deletions
43
libcxx/test/std/experimental/simd/simd.cons/genertor.pass.cpp
This file contains 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,43 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++98, c++03 | ||
|
||
// <experimental/simd> | ||
// | ||
// [simd.class] | ||
// template <class G> explicit simd(G&& gen); | ||
|
||
#include <cstdint> | ||
#include <experimental/simd> | ||
|
||
using namespace std::experimental::parallelism_v2; | ||
|
||
template <class T, class... Args> | ||
auto not_supported_native_simd_ctor(Args&&... args) | ||
-> decltype(native_simd<T>(std::forward<Args>(args)...), void()) = delete; | ||
|
||
template <class T> | ||
void not_supported_native_simd_ctor(...) {} | ||
|
||
template <class T, class... Args> | ||
auto supported_native_simd_ctor(Args&&... args) | ||
-> decltype(native_simd<T>(std::forward<Args>(args)...), void()) {} | ||
|
||
template <class T> | ||
void supported_native_simd_ctor(...) = delete; | ||
|
||
void compile_generator() { | ||
supported_native_simd_ctor<int>([](int i) { return i; }); | ||
not_supported_native_simd_ctor<int>([](int i) { return float(i); }); | ||
not_supported_native_simd_ctor<int>([](intptr_t i) { return (int*)(i); }); | ||
not_supported_native_simd_ctor<int>([](int* i) { return i; }); | ||
} | ||
|
||
int main() {} |
30 changes: 30 additions & 0 deletions
30
libcxx/test/std/experimental/simd/simd.traits/abi_for_size.pass.cpp
This file contains 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,30 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++98, c++03 | ||
|
||
// <experimental/simd> | ||
// | ||
// [simd.traits] | ||
// template <class T, size_t N> struct abi_for_size { using type = see below ; }; | ||
// template <class T, size_t N> using abi_for_size_t = typename abi_for_size<T, N>::type; | ||
|
||
#include <cstdint> | ||
#include <experimental/simd> | ||
|
||
using namespace std::experimental::parallelism_v2; | ||
|
||
static_assert(std::is_same<typename abi_for_size<int, 4>::type, | ||
simd_abi::fixed_size<4>>::value, | ||
""); | ||
|
||
static_assert( | ||
std::is_same<abi_for_size_t<int, 4>, simd_abi::fixed_size<4>>::value, ""); | ||
|
||
int main() {} |
115 changes: 115 additions & 0 deletions
115
libcxx/test/std/experimental/simd/simd.traits/is_abi_tag.pass.cpp
This file contains 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,115 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++98, c++03 | ||
|
||
// <experimental/simd> | ||
// | ||
// [simd.traits] | ||
// template <class T> struct is_abi_tag; | ||
// template <class T> inline constexpr bool is_abi_tag_v = is_abi_tag<T>::value; | ||
|
||
#include <cstdint> | ||
#include <experimental/simd> | ||
#include "test_macros.h" | ||
|
||
using namespace std::experimental::parallelism_v2; | ||
|
||
struct UserType {}; | ||
|
||
static_assert( is_abi_tag<simd_abi::native<int8_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::native<int16_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::native<int32_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::native<int64_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::native<uint8_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::native<uint16_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::native<uint32_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::native<uint64_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::native<float>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::native<double>>::value, ""); | ||
|
||
static_assert( is_abi_tag<simd_abi::compatible<int8_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::compatible<int16_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::compatible<int32_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::compatible<int64_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::compatible<uint8_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::compatible<uint16_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::compatible<uint32_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::compatible<uint64_t>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::compatible<float>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::compatible<double>>::value, ""); | ||
|
||
static_assert( is_abi_tag<simd_abi::scalar>::value, ""); | ||
static_assert(!std::is_same<simd_abi::scalar, simd_abi::fixed_size<1>>::value, | ||
""); | ||
|
||
static_assert( is_abi_tag<simd_abi::fixed_size<1>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::fixed_size<2>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::fixed_size<3>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::fixed_size<4>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::fixed_size<5>>::value, ""); | ||
static_assert( is_abi_tag<simd_abi::fixed_size<32>>::value, ""); | ||
|
||
static_assert(!is_abi_tag<void>::value, ""); | ||
static_assert(!is_abi_tag<int>::value, ""); | ||
static_assert(!is_abi_tag<float>::value, ""); | ||
static_assert(!is_abi_tag<UserType>::value, ""); | ||
static_assert(!is_abi_tag<simd<int>>::value, ""); | ||
static_assert(!is_abi_tag<simd<float>>::value, ""); | ||
static_assert(!is_abi_tag<simd_mask<int>>::value, ""); | ||
static_assert(!is_abi_tag<simd_mask<float>>::value, ""); | ||
|
||
#if TEST_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && \ | ||
!defined(_LIBCPP_HAS_NO_INLINE_VARIABLES) | ||
|
||
static_assert( is_abi_tag_v<simd_abi::native<int8_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::native<int16_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::native<int32_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::native<int64_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::native<uint8_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::native<uint16_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::native<uint32_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::native<uint64_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::native<float>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::native<double>>, ""); | ||
|
||
static_assert( is_abi_tag_v<simd_abi::compatible<int8_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::compatible<int16_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::compatible<int32_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::compatible<int64_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::compatible<uint8_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::compatible<uint16_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::compatible<uint32_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::compatible<uint64_t>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::compatible<float>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::compatible<double>>, ""); | ||
|
||
static_assert( is_abi_tag_v<simd_abi::scalar>, ""); | ||
static_assert(!std::is_same<simd_abi::scalar, simd_abi::fixed_size<1>>::value, | ||
""); | ||
|
||
static_assert( is_abi_tag_v<simd_abi::fixed_size<1>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::fixed_size<2>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::fixed_size<3>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::fixed_size<4>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::fixed_size<5>>, ""); | ||
static_assert( is_abi_tag_v<simd_abi::fixed_size<32>>, ""); | ||
|
||
static_assert(!is_abi_tag_v<void>, ""); | ||
static_assert(!is_abi_tag_v<int>, ""); | ||
static_assert(!is_abi_tag_v<float>, ""); | ||
static_assert(!is_abi_tag_v<UserType>, ""); | ||
static_assert(!is_abi_tag_v<simd<int>>, ""); | ||
static_assert(!is_abi_tag_v<simd<float>>, ""); | ||
static_assert(!is_abi_tag_v<simd_mask<int>>, ""); | ||
static_assert(!is_abi_tag_v<simd_mask<float>>, ""); | ||
|
||
#endif | ||
|
||
int main() {} |
Oops, something went wrong.