]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add helper function to indicate power of two 14564/head
authorPeter Munch <peterrmuench@gmail.com>
Sun, 11 Dec 2022 16:04:53 +0000 (17:04 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Sun, 11 Dec 2022 16:04:53 +0000 (17:04 +0100)
include/deal.II/matrix_free/util.h
source/matrix_free/task_info.cc

index 922e7a1cf29a0e91bae1ae5964957a6f5aa77496..0c6b27bacab1cc5a2b451ecb6d58716fee7648f0 100644 (file)
@@ -161,6 +161,17 @@ namespace internal
 
       return {Quadrature<dim - 1>(), Quadrature<dim - 1>()};
     }
+
+    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
 
index 04b46ea1fc0bdf8f71a72f2fbfa6ba8c57dbd634..d50e46ff85baf445c45ea3cb3ef53252587e1fad 100644 (file)
@@ -24,6 +24,7 @@
 #include <deal.II/lac/dynamic_sparsity_pattern.h>
 
 #include <deal.II/matrix_free/task_info.h>
+#include <deal.II/matrix_free/util.h>
 
 
 #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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.