OSDN Git Service

* stor-layout.c (round_up, round_down): Move ...
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 12 Aug 2004 04:01:04 +0000 (04:01 +0000)
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 12 Aug 2004 04:01:04 +0000 (04:01 +0000)
        * fold-const.c (round_up, round_down): ... here.  Use
        multiple_of_p to avoid any arithmetic at all.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85848 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/stor-layout.c

index 2ab0e90..e3cd92d 100644 (file)
@@ -1,5 +1,11 @@
 2004-08-12  Richard Henderson  <rth@redhat.com>
 
+       * stor-layout.c (round_up, round_down): Move ...
+       * fold-const.c (round_up, round_down): ... here.  Use 
+       multiple_of_p to avoid any arithmetic at all.
+
+2004-08-12  Richard Henderson  <rth@redhat.com>
+
        * gimplify.c (struct gimplify_init_ctor_preeval_data): New.
        (gimplify_init_ctor_preeval_1): New.
        (gimplify_init_ctor_preeval): New.
index 0b225c0..f7e90be 100644 (file)
@@ -10678,4 +10678,74 @@ fold_ignored_result (tree t)
       }
 }
 
+/* Return the value of VALUE, rounded up to a multiple of DIVISOR.
+   This can only be applied to objects of a sizetype.  */
+
+tree
+round_up (tree value, int divisor)
+{
+  tree div, t;
+
+  if (divisor == 0)
+    abort ();
+  if (divisor == 1)
+    return value;
+
+  div = size_int_type (divisor, TREE_TYPE (value));
+
+  /* See if VALUE is already a multiple of DIVISOR.  If so, we don't
+     have to do anything.  */
+  if (multiple_of_p (TREE_TYPE (value), value, div))
+    return value;
+
+  /* If divisor is a power of two, simplify this to bit manipulation.  */
+  if (divisor == (divisor & -divisor))
+    {
+      t = size_int_type (divisor - 1, TREE_TYPE (value));
+      value = size_binop (PLUS_EXPR, value, t);
+      t = size_int_type (-divisor, TREE_TYPE (value));
+      value = size_binop (BIT_AND_EXPR, value, t);
+    }
+  else
+    {
+      value = size_binop (CEIL_DIV_EXPR, value, div);
+      value = size_binop (MULT_EXPR, value, div);
+    }
+
+  return value;
+}
+
+/* Likewise, but round down.  */
+
+tree
+round_down (tree value, int divisor)
+{
+  tree div, t;
+
+  if (divisor == 0)
+    abort ();
+  if (divisor == 1)
+    return value;
+
+  div = size_int_type (divisor, TREE_TYPE (value));
+
+  /* See if VALUE is already a multiple of DIVISOR.  If so, we don't
+     have to do anything.  */
+  if (multiple_of_p (TREE_TYPE (value), value, div))
+    return value;
+
+  /* If divisor is a power of two, simplify this to bit manipulation.  */
+  if (divisor == (divisor & -divisor))
+    {
+      t = size_int_type (-divisor, TREE_TYPE (value));
+      value = size_binop (BIT_AND_EXPR, value, t);
+    }
+  else
+    {
+      value = size_binop (FLOOR_DIV_EXPR, value, div);
+      value = size_binop (MULT_EXPR, value, div);
+    }
+
+  return value;
+}
 #include "gt-fold-const.h"
index 3a0acd7..661cb8b 100644 (file)
@@ -269,64 +269,6 @@ get_mode_alignment (enum machine_mode mode)
   return MIN (BIGGEST_ALIGNMENT, MAX (1, mode_base_align[mode]*BITS_PER_UNIT));
 }
 
-/* Return the value of VALUE, rounded up to a multiple of DIVISOR.
-   This can only be applied to objects of a sizetype.  */
-
-tree
-round_up (tree value, int divisor)
-{
-  tree t;
-
-  if (divisor == 0)
-    abort ();
-  if (divisor == 1)
-    return value;
-
-  /* If divisor is a power of two, simplify this to bit manipulation.  */
-  if (divisor == (divisor & -divisor))
-    {
-      t = size_int_type (divisor - 1, TREE_TYPE (value));
-      value = size_binop (PLUS_EXPR, value, t);
-      t = size_int_type (-divisor, TREE_TYPE (value));
-      value = size_binop (BIT_AND_EXPR, value, t);
-    }
-  else
-    {
-      t = size_int_type (divisor, TREE_TYPE (value));
-      value = size_binop (CEIL_DIV_EXPR, value, t);
-      value = size_binop (MULT_EXPR, value, t);
-    }
-
-  return value;
-}
-
-/* Likewise, but round down.  */
-
-tree
-round_down (tree value, int divisor)
-{
-  tree t;
-
-  if (divisor == 0)
-    abort ();
-  if (divisor == 1)
-    return value;
-
-  /* If divisor is a power of two, simplify this to bit manipulation.  */
-  if (divisor == (divisor & -divisor))
-    {
-      t = size_int_type (-divisor, TREE_TYPE (value));
-      value = size_binop (BIT_AND_EXPR, value, t);
-    }
-  else
-    {
-      t = size_int_type (divisor, TREE_TYPE (value));
-      value = size_binop (FLOOR_DIV_EXPR, value, t);
-      value = size_binop (MULT_EXPR, value, t);
-    }
-
-  return value;
-}
 \f
 /* Subroutine of layout_decl: Force alignment required for the data type.
    But if the decl itself wants greater alignment, don't override that.  */