Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Document black magic about aligned_size for scalars. Thanks Oli on IRC
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 3 Mar 2004 19:19:17 +0000 (19:19 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 3 Mar 2004 19:19:17 +0000 (19:19 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@58 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/DataDesc/ddt_create.c

index 71508a7..63b3473 100644 (file)
@@ -47,15 +47,21 @@ gras_ddt_new_scalar(const char                       *name,
 
   res->size = size>0 ? size : 0;
   
 
   res->size = size>0 ? size : 0;
   
-  if (size>0) { /* Black magic from Oli FIXME: documentation ;)*/
+  if (size>0) { 
     long int sz   = size;
     long int mask = sz;
     long int sz   = size;
     long int mask = sz;
+
+    /* just in case you wonder, x>>1 == x/2 on all architecture when x>=0 */
+
+    /* make sure mask have all the bits under the biggest one of size set to 1
+       Example: size=000100101 => mask=0000111111 */
     while ((sz >>= 1)) {
       mask |= sz;
     }
 
     while ((sz >>= 1)) {
       mask |= sz;
     }
 
-    if (size & (mask >> 1)) {
+    if (size & (mask >> 1)) { /* if size have bits to one beside its biggest */
+      /* size is not a power of 2 */
+      /* alignment= next power of 2 after size */
       res->alignment = (size & ~(mask >> 1)) << 1;
       gras_assert0(res->alignment != 0,
                   "scalar type too large");
       res->alignment = (size & ~(mask >> 1)) << 1;
       gras_assert0(res->alignment != 0,
                   "scalar type too large");
@@ -65,8 +71,9 @@ gras_ddt_new_scalar(const char                       *name,
                    "scalar type too large");
       
     } else {
                    "scalar type too large");
       
     } else {
-      res->alignment       = size & ~(mask >> 1);;
-      res->aligned_size    = aligned(size, res->alignment);
+      /* size is a power of 2, life is great */
+      res->alignment       = size;
+      res->aligned_size    = size;
     }
     
   } else {
     }
     
   } else {