From: Peter Munch Date: Sun, 11 Dec 2022 16:04:53 +0000 (+0100) Subject: Add helper function to indicate power of two X-Git-Tag: v9.5.0-rc1~735^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14564%2Fhead;p=dealii.git Add helper function to indicate power of two --- diff --git a/include/deal.II/matrix_free/util.h b/include/deal.II/matrix_free/util.h index 922e7a1cf2..0c6b27baca 100644 --- a/include/deal.II/matrix_free/util.h +++ b/include/deal.II/matrix_free/util.h @@ -161,6 +161,17 @@ namespace internal return {Quadrature(), Quadrature()}; } + + inline DEAL_II_ALWAYS_INLINE unsigned int + indicate_power_of_two(const unsigned int vectorization_length) + { + unsigned int vectorization_length_bits = 0; + unsigned int my_length = vectorization_length; + while (my_length >>= 1) + ++vectorization_length_bits; + return 1 << vectorization_length_bits; + } + } // end of namespace MatrixFreeFunctions } // end of namespace internal diff --git a/source/matrix_free/task_info.cc b/source/matrix_free/task_info.cc index 04b46ea1fc..d50e46ff85 100644 --- a/source/matrix_free/task_info.cc +++ b/source/matrix_free/task_info.cc @@ -24,6 +24,7 @@ #include #include +#include #ifdef DEAL_II_WITH_TBB @@ -825,11 +826,7 @@ namespace internal // Give the compiler a chance to detect that vectorization_length is a // power of two, which allows it to replace integer divisions by shifts - unsigned int vectorization_length_bits = 0; - unsigned int my_length = vectorization_length; - while ((my_length >>= 1) != 0u) - ++vectorization_length_bits; - const unsigned int n_lanes = 1 << vectorization_length_bits; + const unsigned int n_lanes = indicate_power_of_two(vectorization_length); // Step 1: find tight map of categories for not taking exceeding amounts // of memory below. Sort the new categories by the numbers in the