OSDN Git Service

Fix aliasing bug that also caused memory usage problems.
[pf3gnuchains/gcc-fork.git] / gcc / genautomata.c
index 179564a..292a2de 100644 (file)
@@ -1,5 +1,5 @@
 /* Pipeline hazard description translator.
-   Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    Written by Vladimir Makarov <vmakarov@redhat.com>
 
@@ -1209,7 +1209,7 @@ struct ainsn
   ainsn_t next_equiv_class_insn;
   /* The following field value is nonzero if the insn declaration is
      the first insn declaration with given equivalence number.  */
-  char first_ainsn_with_given_equialence_num;
+  char first_ainsn_with_given_equivalence_num;
   /* The following field is number of class of equivalence of insns.
      It is necessary because many insns may be equivalent with the
      point of view of pipeline hazards.  */
@@ -6610,7 +6610,7 @@ set_insn_equiv_classes (automaton_t automaton)
         first_insn = ainsn;
         if (!first_insn->first_insn_with_same_reservs)
          abort ();
-        first_insn->first_ainsn_with_given_equialence_num = 1;
+        first_insn->first_ainsn_with_given_equivalence_num = 1;
         curr_insn = first_insn;
         do
           {
@@ -7578,6 +7578,7 @@ add_vect (state_ainsn_table_t tab, int vect_num, vect_el_t *vect,
   int no_state_value;
   vect_el_t vect_el;
   int i;
+  unsigned long vect_mask, comb_vect_mask;
 
   if (vect_length == 0)
     abort ();
@@ -7599,23 +7600,77 @@ add_vect (state_ainsn_table_t tab, int vect_num, vect_el_t *vect,
        first_unempty_vect_index++)
     if (vect [first_unempty_vect_index] != undefined_vect_el_value)
       break;
+
   /* Search for the place in comb vect for the inserted vect.  */
-  for (comb_vect_index = 0;
-       comb_vect_index < comb_vect_els_num;
-       comb_vect_index++)
-    {
-      for (vect_index = first_unempty_vect_index;
-           vect_index < vect_length
-             && vect_index + comb_vect_index < comb_vect_els_num;
-           vect_index++)
-        if (vect [vect_index] != undefined_vect_el_value
-            && (comb_vect_start [vect_index + comb_vect_index]
-               != undefined_vect_el_value))
-          break;
-      if (vect_index >= vect_length
-          || vect_index + comb_vect_index >= comb_vect_els_num)
-        break;
+
+  /* Slow case.  */
+  if (vect_length - first_unempty_vect_index >= SIZEOF_LONG * CHAR_BIT)
+    {
+      for (comb_vect_index = 0;
+           comb_vect_index < comb_vect_els_num;
+           comb_vect_index++)
+        {
+          for (vect_index = first_unempty_vect_index;
+               vect_index < vect_length
+               && vect_index + comb_vect_index < comb_vect_els_num;
+               vect_index++)
+            if (vect [vect_index] != undefined_vect_el_value
+                && (comb_vect_start [vect_index + comb_vect_index]
+                   != undefined_vect_el_value))
+              break;
+          if (vect_index >= vect_length
+              || vect_index + comb_vect_index >= comb_vect_els_num)
+            break;
+        }
+      goto found;
+    }
+
+  /* Fast case.  */
+  vect_mask = 0;
+  for (vect_index = first_unempty_vect_index;
+       vect_index < vect_length;
+       vect_index++)
+    {
+      vect_mask = vect_mask << 1;
+      if (vect [vect_index] != undefined_vect_el_value)
+       vect_mask |= 1;
     }
+
+  /* Search for the place in comb vect for the inserted vect.  */
+  comb_vect_index = 0;
+  if (comb_vect_els_num == 0)
+    goto found;
+
+  comb_vect_mask = 0;
+  for (vect_index = first_unempty_vect_index;
+       vect_index < vect_length && vect_index < comb_vect_els_num;
+       vect_index++)
+    {
+      comb_vect_mask <<= 1;
+      if (vect_index + comb_vect_index < comb_vect_els_num
+         && comb_vect_start [vect_index + comb_vect_index]
+            != undefined_vect_el_value)
+       comb_vect_mask |= 1;
+    }
+  if ((vect_mask & comb_vect_mask) == 0)
+    goto found;
+
+  for (comb_vect_index = 1, i = vect_length; i < comb_vect_els_num;
+       comb_vect_index++, i++)
+    {
+      comb_vect_mask = (comb_vect_mask << 1) | 1;
+      comb_vect_mask ^= comb_vect_start [i] == undefined_vect_el_value;
+      if ((vect_mask & comb_vect_mask) == 0)
+       goto found;
+    }
+  for ( ; comb_vect_index < comb_vect_els_num; comb_vect_index++)
+    {
+      comb_vect_mask <<= 1;
+      if ((vect_mask & comb_vect_mask) == 0)
+       goto found;
+    }
+
+found:
   /* Slot was found.  */
   additional_els_num = comb_vect_index + real_vect_length - comb_vect_els_num;
   if (additional_els_num < 0)
@@ -7673,7 +7728,7 @@ out_state_arcs_num (state_t state)
     {
       if (arc->insn == NULL)
        abort ();
-      if (arc->insn->first_ainsn_with_given_equialence_num)
+      if (arc->insn->first_ainsn_with_given_equivalence_num)
         result++;
     }
   return result;
@@ -7756,7 +7811,7 @@ output_trans_table (automaton_t automaton)
         {
           if (arc->insn == NULL)
            abort ();
-          if (arc->insn->first_ainsn_with_given_equialence_num)
+          if (arc->insn->first_ainsn_with_given_equivalence_num)
             add_vect_el (&transition_vect, arc->insn,
                          arc->to_state->order_state_num);
         }
@@ -7805,7 +7860,7 @@ output_state_alts_table (automaton_t automaton)
         {
           if (arc->insn == NULL)
            abort ();
-          if (arc->insn->first_ainsn_with_given_equialence_num)
+          if (arc->insn->first_ainsn_with_given_equivalence_num)
             add_vect_el (&state_alts_vect, arc->insn, arc->state_alts);
         }
       add_vect (automaton->state_alts_table, (*state_ptr)->order_state_num,
@@ -7914,7 +7969,7 @@ output_min_issue_delay_table (automaton_t automaton)
     VLA_HWINT (min_issue_delay_vect, i) = 0;
   automaton->max_min_delay = 0;
   for (ainsn = automaton->ainsn_list; ainsn != NULL; ainsn = ainsn->next_ainsn)
-    if (ainsn->first_ainsn_with_given_equialence_num)
+    if (ainsn->first_ainsn_with_given_equivalence_num)
       {
        for (state_ptr = VLA_PTR_BEGIN (output_states_vect);
             state_ptr <= (state_t *) VLA_PTR_LAST (output_states_vect);
@@ -9117,7 +9172,7 @@ output_automaton_units (automaton_t automaton)
   int there_is_an_automaton_unit;
   int i;
 
-  fprintf (output_description_file, "\n  Coresponding units:\n");
+  fprintf (output_description_file, "\n  Corresponding units:\n");
   fprintf (output_description_file, "    ");
   curr_line_length = 4;
   there_is_an_automaton_unit = 0;