From: peterrum Date: Sun, 28 Jul 2019 13:06:22 +0000 (+0200) Subject: Add two new methods to VectorizedArray X-Git-Tag: v9.2.0-rc1~1344^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdd6aea60dd69a1abdd4e7419e5f1f6f56a89010;p=dealii.git Add two new methods to VectorizedArray --- diff --git a/doc/news/changes/minor/20190729PeterMunch b/doc/news/changes/minor/20190729PeterMunch new file mode 100644 index 0000000000..e8ed0a0a59 --- /dev/null +++ b/doc/news/changes/minor/20190729PeterMunch @@ -0,0 +1,4 @@ +New: Amend VectorizedArray with a default constructor and +a constructor taking a scalar value. +
+(Peter Munch, 2019/07/29) diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index 2c4252560d..8b54f3b69a 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -3536,16 +3536,7 @@ operator*(const SymmetricTensor &t, // (as well as with switched arguments and double<->float). using product_type = typename ProductType::type; SymmetricTensor tt(t); - // we used to shorten the following by 'tt *= product_type(factor);' - // which requires that a converting constructor - // 'product_type::product_type(const OtherNumber) is defined. - // however, a user-defined constructor is not allowed for aggregates, - // e.g. VectorizedArray. therefore, we work around this issue using a - // copy-assignment operator 'product_type::operator=(const OtherNumber)' - // which we assume to be defined. - product_type new_factor; - new_factor = factor; - tt *= new_factor; + tt *= product_type(factor); return tt; } diff --git a/include/deal.II/base/vectorization.h b/include/deal.II/base/vectorization.h index c582929593..3af4a2adc5 100644 --- a/include/deal.II/base/vectorization.h +++ b/include/deal.II/base/vectorization.h @@ -224,6 +224,20 @@ public: // POD means that there should be no user-defined constructors, destructors // and copy functions (the standard is somewhat relaxed in C++2011, though). + /** + * Default empty constructor, leaving the data in an uninitialized state + * similar to float/double. + */ + VectorizedArray() = default; + + /** + * Construct an array with the given scalar broadcast to all lanes + */ + VectorizedArray(const Number scalar) + { + this->operator=(scalar); + } + /** * This function assigns a scalar to this class. */ @@ -666,6 +680,20 @@ public: */ static const unsigned int n_array_elements = 8; + /** + * Default empty constructor, leaving the data in an uninitialized state + * similar to float/double. + */ + VectorizedArray() = default; + + /** + * Construct an array with the given scalar broadcast to all lanes + */ + VectorizedArray(const double scalar) + { + this->operator=(scalar); + } + /** * This function can be used to set all data fields to a given scalar. */ @@ -1085,6 +1113,20 @@ public: */ static const unsigned int n_array_elements = 16; + /** + * Default empty constructor, leaving the data in an uninitialized state + * similar to float/double. + */ + VectorizedArray() = default; + + /** + * Construct an array with the given scalar broadcast to all lanes + */ + VectorizedArray(const float scalar) + { + this->operator=(scalar); + } + /** * This function can be used to set all data fields to a given scalar. */ @@ -1555,6 +1597,20 @@ public: */ static const unsigned int n_array_elements = 4; + /** + * Default empty constructor, leaving the data in an uninitialized state + * similar to float/double. + */ + VectorizedArray() = default; + + /** + * Construct an array with the given scalar broadcast to all lanes + */ + VectorizedArray(const double scalar) + { + this->operator=(scalar); + } + /** * This function can be used to set all data fields to a given scalar. */ @@ -1943,6 +1999,20 @@ public: */ static const unsigned int n_array_elements = 8; + /** + * Default empty constructor, leaving the data in an uninitialized state + * similar to float/double. + */ + VectorizedArray() = default; + + /** + * Construct an array with the given scalar broadcast to all lanes + */ + VectorizedArray(const float scalar) + { + this->operator=(scalar); + } + /** * This function can be used to set all data fields to a given scalar. */ @@ -2352,6 +2422,20 @@ public: */ static const unsigned int n_array_elements = 2; + /** + * Default empty constructor, leaving the data in an uninitialized state + * similar to float/double. + */ + VectorizedArray() = default; + + /** + * Construct an array with the given scalar broadcast to all lanes + */ + VectorizedArray(const double scalar) + { + this->operator=(scalar); + } + /** * This function can be used to set all data fields to a given scalar. */ @@ -2703,6 +2787,20 @@ public: * This function can be used to set all data fields to a given scalar. */ + /** + * Default empty constructor, leaving the data in an uninitialized state + * similar to float/double. + */ + VectorizedArray() = default; + + /** + * Construct an array with the given scalar broadcast to all lanes + */ + VectorizedArray(const float scalar) + { + this->operator=(scalar); + } + DEAL_II_ALWAYS_INLINE VectorizedArray & operator=(const float x) @@ -3067,6 +3165,20 @@ public: */ static const unsigned int n_array_elements = 2; + /** + * Default empty constructor, leaving the data in an uninitialized state + * similar to float/double. + */ + VectorizedArray() = default; + + /** + * Construct an array with the given scalar broadcast to all lanes + */ + VectorizedArray(const double scalar) + { + this->operator=(scalar); + } + /** * This function assigns a scalar to this class. */ @@ -3285,6 +3397,20 @@ public: */ static const unsigned int n_array_elements = 4; + /** + * Default empty constructor, leaving the data in an uninitialized state + * similar to float/double. + */ + VectorizedArray() = default; + + /** + * Construct an array with the given scalar broadcast to all lanes + */ + VectorizedArray(const float scalar) + { + this->operator=(scalar); + } + /** * This function assigns a scalar to this class. */ diff --git a/tests/base/vectorization_make_vectorized_array_01.cc b/tests/base/vectorization_11.cc similarity index 84% rename from tests/base/vectorization_make_vectorized_array_01.cc rename to tests/base/vectorization_11.cc index 9067b826ba..f6b76d3a01 100644 --- a/tests/base/vectorization_make_vectorized_array_01.cc +++ b/tests/base/vectorization_11.cc @@ -52,20 +52,25 @@ struct Tester test() { do_test(make_vectorized_array(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); #if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && defined(__AVX512F__) do_test(make_vectorized_array>(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); #endif #if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 2 && defined(__AVX__) do_test(make_vectorized_array>(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); #endif #if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__SSE2__) do_test(make_vectorized_array>(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); #endif do_test(make_vectorized_array>(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); } }; @@ -76,20 +81,25 @@ struct Tester test() { do_test(make_vectorized_array(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); #if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 3 && defined(__AVX512F__) do_test(make_vectorized_array>(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); #endif #if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 2 && defined(__AVX__) do_test(make_vectorized_array>(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); #endif #if DEAL_II_COMPILER_VECTORIZATION_LEVEL >= 1 && defined(__SSE2__) do_test(make_vectorized_array>(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); #endif do_test(make_vectorized_array>(2.0), 2.0); + do_test(VectorizedArray(2.0), 2.0); } }; diff --git a/tests/base/vectorization_make_vectorized_array_01.output b/tests/base/vectorization_11.output similarity index 55% rename from tests/base/vectorization_make_vectorized_array_01.output rename to tests/base/vectorization_11.output index bb0c0e3cbe..4aa88b6fe4 100644 --- a/tests/base/vectorization_make_vectorized_array_01.output +++ b/tests/base/vectorization_11.output @@ -2,6 +2,10 @@ DEAL::double: DEAL:: test 1 array elements DEAL:: test 1 array elements +DEAL:: test 1 array elements +DEAL:: test 1 array elements DEAL::float: DEAL:: test 1 array elements DEAL:: test 1 array elements +DEAL:: test 1 array elements +DEAL:: test 1 array elements diff --git a/tests/base/vectorization_make_vectorized_array_01.output.avx b/tests/base/vectorization_11.output.avx similarity index 52% rename from tests/base/vectorization_make_vectorized_array_01.output.avx rename to tests/base/vectorization_11.output.avx index 4951c758d0..431f41e210 100644 --- a/tests/base/vectorization_make_vectorized_array_01.output.avx +++ b/tests/base/vectorization_11.output.avx @@ -2,10 +2,18 @@ DEAL::double: DEAL:: test 4 array elements DEAL:: test 4 array elements +DEAL:: test 4 array elements +DEAL:: test 4 array elements DEAL:: test 2 array elements +DEAL:: test 2 array elements +DEAL:: test 1 array elements DEAL:: test 1 array elements DEAL::float: DEAL:: test 8 array elements DEAL:: test 8 array elements +DEAL:: test 8 array elements +DEAL:: test 8 array elements DEAL:: test 4 array elements +DEAL:: test 4 array elements +DEAL:: test 1 array elements DEAL:: test 1 array elements diff --git a/tests/base/vectorization_make_vectorized_array_01.output.avx512 b/tests/base/vectorization_11.output.avx512 similarity index 52% rename from tests/base/vectorization_make_vectorized_array_01.output.avx512 rename to tests/base/vectorization_11.output.avx512 index 225e32e773..8d0eca80cb 100644 --- a/tests/base/vectorization_make_vectorized_array_01.output.avx512 +++ b/tests/base/vectorization_11.output.avx512 @@ -2,12 +2,22 @@ DEAL::double: DEAL:: test 8 array elements DEAL:: test 8 array elements +DEAL:: test 8 array elements +DEAL:: test 8 array elements +DEAL:: test 4 array elements DEAL:: test 4 array elements DEAL:: test 2 array elements +DEAL:: test 2 array elements +DEAL:: test 1 array elements DEAL:: test 1 array elements DEAL::float: DEAL:: test 16 array elements DEAL:: test 16 array elements +DEAL:: test 16 array elements +DEAL:: test 16 array elements +DEAL:: test 8 array elements DEAL:: test 8 array elements DEAL:: test 4 array elements +DEAL:: test 4 array elements +DEAL:: test 1 array elements DEAL:: test 1 array elements diff --git a/tests/base/vectorization_make_vectorized_array_01.output.sse2 b/tests/base/vectorization_11.output.sse2 similarity index 53% rename from tests/base/vectorization_make_vectorized_array_01.output.sse2 rename to tests/base/vectorization_11.output.sse2 index fffb0c67e3..60dc91825f 100644 --- a/tests/base/vectorization_make_vectorized_array_01.output.sse2 +++ b/tests/base/vectorization_11.output.sse2 @@ -2,8 +2,14 @@ DEAL::double: DEAL:: test 2 array elements DEAL:: test 2 array elements +DEAL:: test 2 array elements +DEAL:: test 2 array elements +DEAL:: test 1 array elements DEAL:: test 1 array elements DEAL::float: DEAL:: test 4 array elements DEAL:: test 4 array elements +DEAL:: test 4 array elements +DEAL:: test 4 array elements +DEAL:: test 1 array elements DEAL:: test 1 array elements