]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Replace reinterpret_cast by static_cast in access to individual elements of vectorize...
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Wed, 12 Dec 2012 14:19:47 +0000 (14:19 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Wed, 12 Dec 2012 14:19:47 +0000 (14:19 +0000)
git-svn-id: https://svn.dealii.org/trunk@27799 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/vectorization.h

index 28403b7d48d53f468941f17dd27490a80916adf1..f5830f514f1e613aacb00d68fede95abd353916a 100644 (file)
@@ -103,7 +103,10 @@ public:
   operator [] (const unsigned int comp)
   {
     AssertIndexRange (comp, 4);
-    return *(reinterpret_cast<double *>(&data)+comp);
+    // __m256d stores doubles in adjacent memory blocks. to access one double
+    // data field at a time, first cast the address of the given data field to
+    // void* and then back to double*.
+    return *(static_cast<double *>(static_cast<void *>(&data))+comp);
   }
 
   /**
@@ -113,7 +116,7 @@ public:
   operator [] (const unsigned int comp) const
   {
     AssertIndexRange (comp, 4);
-    return *(reinterpret_cast<const double *>(&data)+comp);
+    return *(static_cast<const double *>(static_cast<const void *>(&data))+comp);
   }
 
   /**
@@ -286,7 +289,7 @@ public:
   operator [] (const unsigned int comp)
   {
     AssertIndexRange (comp, 8);
-    return *(reinterpret_cast<float *>(&data)+comp);
+    return *(static_cast<float *>(static_cast<void *>(&data))+comp);
   }
 
   /**
@@ -296,7 +299,7 @@ public:
   operator [] (const unsigned int comp) const
   {
     AssertIndexRange (comp, 8);
-    return *(reinterpret_cast<const float *>(&data)+comp);
+    return *(static_cast<const float *>(static_cast<const void *>(&data))+comp);
   }
 
   /**
@@ -472,7 +475,7 @@ public:
   operator [] (const unsigned int comp)
   {
     AssertIndexRange (comp, 2);
-    return *(reinterpret_cast<double *>(&data)+comp);
+    return *(static_cast<double *>(static_cast<void *>(&data))+comp);
   }
 
   /**
@@ -482,7 +485,7 @@ public:
   operator [] (const unsigned int comp) const
   {
     AssertIndexRange (comp, 2);
-    return *(reinterpret_cast<const double *>(&data)+comp);
+    return *(static_cast<const double *>(static_cast<const void *>(&data))+comp);
   }
 
   /**
@@ -651,7 +654,7 @@ public:
   operator [] (const unsigned int comp)
   {
     AssertIndexRange (comp, 4);
-    return *(reinterpret_cast<float *>(&data)+comp);
+    return *(static_cast<float *>(static_cast<void *>(&data))+comp);
   }
 
   /**
@@ -661,7 +664,7 @@ public:
   operator [] (const unsigned int comp) const
   {
     AssertIndexRange (comp, 4);
-    return *(reinterpret_cast<const float *>(&data)+comp);;
+    return *(static_cast<const float *>(static_cast<const void *>(&data))+comp);
   }
 
   /**

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.