binutils: support for the SPARC M8 processor
[deliverable/binutils-gdb.git] / sim / common / cgen-scache.c
index c5ea075a9f1818c69485e023832e6da34dc59d4a..d2cbc069655dcddab77ca663656a17c195f92a8b 100644 (file)
@@ -1,22 +1,21 @@
 /* Simulator cache routines for CGEN simulators (and maybe others).
 /* Simulator cache routines for CGEN simulators (and maybe others).
-   Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1996-2017 Free Software Foundation, Inc.
    Contributed by Cygnus Support.
 
 This file is part of GDB, the GNU debugger.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
    Contributed by Cygnus Support.
 
 This file is part of GDB, the GNU debugger.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #define SCACHE_DEFINE_INLINE
 
 
 #define SCACHE_DEFINE_INLINE
 
@@ -28,8 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "sim-options.h"
 #include "sim-io.h"
 
 #include "sim-options.h"
 #include "sim-io.h"
 
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-
 /* Unused address.  */
 #define UNUSED_ADDR 0xffffffff
 
 /* Unused address.  */
 #define UNUSED_ADDR 0xffffffff
 
@@ -117,8 +114,6 @@ static SIM_RC
 scache_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
                       char *arg, int is_command)
 {
 scache_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
                       char *arg, int is_command)
 {
-  int n;
-
   switch (opt)
     {
     case 'c' :
   switch (opt)
     {
     case 'c' :
@@ -126,24 +121,26 @@ scache_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
        {
          if (arg != NULL)
            {
        {
          if (arg != NULL)
            {
-             int n = strtol (arg, NULL, 0);
+             unsigned int n = (unsigned int) strtoul (arg, NULL, 0);
              if (n < MIN_SCACHE_SIZE)
                {
              if (n < MIN_SCACHE_SIZE)
                {
-                 sim_io_eprintf (sd, "invalid scache size `%d', must be at least 4", n);
+                 sim_io_eprintf (sd, "invalid scache size `%u', must be at least %u",
+                                 n, MIN_SCACHE_SIZE);
                  return SIM_RC_FAIL;
                }
              /* Ensure it's a multiple of 2.  */
              if ((n & (n - 1)) != 0)
                {
                  return SIM_RC_FAIL;
                }
              /* Ensure it's a multiple of 2.  */
              if ((n & (n - 1)) != 0)
                {
-                 sim_io_eprintf (sd, "scache size `%d' not a multiple of 2\n", n);
-                 {
-                   /* round up to nearest multiple of 2 */
-                   int i;
-                   for (i = 1; i < n; i <<= 1)
-                     continue;
-                   n = i;
-                 }
-                 sim_io_eprintf (sd, "rounding scache size up to %d\n", n);
+                 unsigned int i;
+                 sim_io_eprintf (sd, "scache size `%u' not a multiple of 2\n", n);
+                 /* Round up to nearest multiple of 2.  */
+                 for (i = 1; i && i < n; i <<= 1)
+                   continue;
+                 if (i)
+                   {
+                     n = i;
+                     sim_io_eprintf (sd, "rounding scache size up to %u\n", n);
+                   }
                }
              if (cpu == NULL)
                STATE_SCACHE_SIZE (sd) = n;
                }
              if (cpu == NULL)
                STATE_SCACHE_SIZE (sd) = n;
@@ -215,7 +212,7 @@ scache_init (SIM_DESC sd)
 #if WITH_SCACHE_PBB
          CPU_SCACHE_MAX_CHAIN_LENGTH (cpu) = MAX_CHAIN_LENGTH;
          CPU_SCACHE_NUM_HASH_CHAIN_ENTRIES (cpu) = MAX_HASH_CHAIN_LENGTH;
 #if WITH_SCACHE_PBB
          CPU_SCACHE_MAX_CHAIN_LENGTH (cpu) = MAX_CHAIN_LENGTH;
          CPU_SCACHE_NUM_HASH_CHAIN_ENTRIES (cpu) = MAX_HASH_CHAIN_LENGTH;
-         CPU_SCACHE_NUM_HASH_CHAINS (cpu) = MAX (MIN_HASH_CHAINS,
+         CPU_SCACHE_NUM_HASH_CHAINS (cpu) = max (MIN_HASH_CHAINS,
                                                  CPU_SCACHE_SIZE (cpu)
                                                  / SCACHE_HASH_RATIO);
          CPU_SCACHE_HASH_TABLE (cpu) =
                                                  CPU_SCACHE_SIZE (cpu)
                                                  / SCACHE_HASH_RATIO);
          CPU_SCACHE_HASH_TABLE (cpu) =
@@ -313,6 +310,8 @@ scache_flush_cpu (SIM_CPU *cpu)
 SCACHE *
 scache_lookup (SIM_CPU *cpu, IADDR pc)
 {
 SCACHE *
 scache_lookup (SIM_CPU *cpu, IADDR pc)
 {
+  /* FIXME: hash computation is wrong, doesn't take into account
+     NUM_HASH_CHAIN_ENTRIES.  A lot of the hash table will be unused!  */
   unsigned int slot = HASH_PC (pc) & (CPU_SCACHE_NUM_HASH_CHAINS (cpu) - 1);
   int i, max_i = CPU_SCACHE_NUM_HASH_CHAIN_ENTRIES (cpu);
   SCACHE_MAP *scm;
   unsigned int slot = HASH_PC (pc) & (CPU_SCACHE_NUM_HASH_CHAINS (cpu) - 1);
   int i, max_i = CPU_SCACHE_NUM_HASH_CHAIN_ENTRIES (cpu);
   SCACHE_MAP *scm;
@@ -343,6 +342,8 @@ scache_lookup (SIM_CPU *cpu, IADDR pc)
 SCACHE *
 scache_lookup_or_alloc (SIM_CPU *cpu, IADDR pc, int n, SCACHE **bufp)
 {
 SCACHE *
 scache_lookup_or_alloc (SIM_CPU *cpu, IADDR pc, int n, SCACHE **bufp)
 {
+  /* FIXME: hash computation is wrong, doesn't take into account
+     NUM_HASH_CHAIN_ENTRIES.  A lot of the hash table will be unused!  */
   unsigned int slot = HASH_PC (pc) & (CPU_SCACHE_NUM_HASH_CHAINS (cpu) - 1);
   int i, max_i = CPU_SCACHE_NUM_HASH_CHAIN_ENTRIES (cpu);
   SCACHE_MAP *scm;
   unsigned int slot = HASH_PC (pc) & (CPU_SCACHE_NUM_HASH_CHAINS (cpu) - 1);
   int i, max_i = CPU_SCACHE_NUM_HASH_CHAIN_ENTRIES (cpu);
   SCACHE_MAP *scm;
@@ -372,6 +373,7 @@ scache_lookup_or_alloc (SIM_CPU *cpu, IADDR pc, int n, SCACHE **bufp)
       static int next_free = 0;
 
       scm = & CPU_SCACHE_HASH_TABLE (cpu) [slot];
       static int next_free = 0;
 
       scm = & CPU_SCACHE_HASH_TABLE (cpu) [slot];
+      /* FIXME: This seems rather clumsy.  */
       for (i = 0; i < next_free; ++i, ++scm)
        continue;
       ++next_free;
       for (i = 0; i < next_free; ++i, ++scm)
        continue;
       ++next_free;
@@ -381,6 +383,8 @@ scache_lookup_or_alloc (SIM_CPU *cpu, IADDR pc, int n, SCACHE **bufp)
 
   /* At this point SCM points to the hash table entry to use.
      Now make sure there's room in the cache.  */
 
   /* At this point SCM points to the hash table entry to use.
      Now make sure there's room in the cache.  */
+  /* FIXME: Kinda weird to use a next_free adjusted scm when cache is
+     flushed.  */
 
   {
     int elm_size = IMP_PROPS_SCACHE_ELM_SIZE (MACH_IMP_PROPS (CPU_MACH (cpu)));
 
   {
     int elm_size = IMP_PROPS_SCACHE_ELM_SIZE (MACH_IMP_PROPS (CPU_MACH (cpu)));
@@ -461,7 +465,7 @@ scache_print_profile (SIM_CPU *cpu, int verbose)
                         i,
                         max_val < 10000 ? 5 : 10,
                         sim_add_commas (buf, sizeof (buf), lengths[i]));
                         i,
                         max_val < 10000 ? 5 : 10,
                         sim_add_commas (buf, sizeof (buf), lengths[i]));
-         sim_profile_print_bar (sd, PROFILE_HISTOGRAM_WIDTH,
+         sim_profile_print_bar (sd, cpu, PROFILE_HISTOGRAM_WIDTH,
                                 lengths[i], max_val);
          sim_io_printf (sd, "\n");
        }
                                 lengths[i], max_val);
          sim_io_printf (sd, "\n");
        }
This page took 0.026134 seconds and 4 git commands to generate.