OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [cuc/] [cuc.c] - Diff between revs 1244 and 1308

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 1244 Rev 1308
Line 22... Line 22...
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdarg.h>
#include <assert.h>
#include <assert.h>
#include <ctype.h>
#include <ctype.h>
 
#include <string.h>
 
#include <unistd.h>
 
 
 
#include "abstract.h"
#include "sim-config.h"
#include "sim-config.h"
#include "cuc.h"
#include "cuc.h"
#include "insn.h"
#include "insn.h"
#include "profiler.h"
#include "profiler.h"
#include "opcode/or32.h"
#include "opcode/or32.h"
#include "parse.h"
#include "parse.h"
 
#include "debug.h"
 
 
FILE *flog;
FILE *flog;
int cuc_debug = 0;
int cuc_debug = 0;
 
 
/* Last used registers by software convention */
/* Last used registers by software convention */
Line 393... Line 398...
}
}
 
 
/* Generates a function, based on specified parameters */
/* Generates a function, based on specified parameters */
cuc_func *generate_function (cuc_func *rf, char *name, char *cut_filename)
cuc_func *generate_function (cuc_func *rf, char *name, char *cut_filename)
{
{
  int b, i, j;
  int b;
  char tmp[256];
  char tmp[256];
  cuc_timings tt;
  cuc_timings tt;
  cuc_func *f;
  cuc_func *f;
  assert (f = dup_func (rf));
  assert (f = dup_func (rf));
 
 
Line 436... Line 441...
}
}
 
 
/* Calculates required time, based on selected options */
/* Calculates required time, based on selected options */
int calc_cycles (cuc_func *f)
int calc_cycles (cuc_func *f)
{
{
  int b, i, ntime = f->timings.new_time;
  int b, ntime = f->timings.new_time;
  for (b = 0; b < f->num_bb; b++)
  for (b = 0; b < f->num_bb; b++)
    if (f->bb[b].selected_tim >= 0) {
    if (f->bb[b].selected_tim >= 0) {
      assert (f->bb[b].selected_tim < f->bb[b].ntim);
      assert (f->bb[b].selected_tim < f->bb[b].ntim);
      ntime += f->bb[b].tim[f->bb[b].selected_tim].new_time - f->timings.new_time;
      ntime += f->bb[b].tim[f->bb[b].selected_tim].new_time - f->timings.new_time;
    }
    }
Line 448... Line 453...
}
}
 
 
/* Calculates required size, based on selected options */
/* Calculates required size, based on selected options */
double calc_size (cuc_func *f)
double calc_size (cuc_func *f)
{
{
  int b, i;
  int b;
  double size = f->timings.size;
  double size = f->timings.size;
  for (b = 0; b < f->num_bb; b++)
  for (b = 0; b < f->num_bb; b++)
    if (f->bb[b].selected_tim >= 0) {
    if (f->bb[b].selected_tim >= 0) {
      assert (f->bb[b].selected_tim < f->bb[b].ntim);
      assert (f->bb[b].selected_tim < f->bb[b].ntim);
      size += f->bb[b].tim[f->bb[b].selected_tim].size - f->timings.size;
      size += f->bb[b].tim[f->bb[b].selected_tim].size - f->timings.size;
Line 473... Line 478...
    int index = insn_decode (d);
    int index = insn_decode (d);
    assert (index >= 0);
    assert (index >= 0);
    if (x) x++;
    if (x) x++;
    if (strcmp (insn_name (index), "l.jr") == 0) x = 1;
    if (strcmp (insn_name (index), "l.jr") == 0) x = 1;
    a += 4;
    a += 4;
    fprintf (fo, "%08x\n", d);
    fprintf (fo, "%08lx\n", d);
  } while (x < 2);
  } while (x < 2);
 
 
  fclose (fo);
  fclose (fo);
  return a - 4;
  return a - 4;
}
}
Line 499... Line 504...
        if (ii->index == II_CALL) {
        if (ii->index == II_CALL) {
          assert (ii->opt[0] == OPT_CONST);
          assert (ii->opt[0] == OPT_CONST);
          for (j = 0; j < prof_nfuncs - 1; j++)
          for (j = 0; j < prof_nfuncs - 1; j++)
            if (func[j] && func[j]->start_addr == ii->op[0]) break;
            if (func[j] && func[j]->start_addr == ii->op[0]) break;
          if (j >= prof_nfuncs - 1) {
          if (j >= prof_nfuncs - 1) {
            log ("%s is calling unknown function, address %08x\n",
            log ("%s is calling unknown function, address %08lx\n",
                            prof_func[f].name, ii->op[0]);
                            prof_func[f].name, ii->op[0]);
            debug (1, "%s is calling unknown function, address %08x\n",
            debug (1, "%s is calling unknown function, address %08x\n",
                            prof_func[f].name, ii->op[0]);
                            prof_func[f].name, ii->op[0]);
            free_func (func[f]);
            free_func (func[f]);
            func[f] = NULL;
            func[f] = NULL;
Line 600... Line 605...
 
 
    /* Extract the function from the binary */
    /* Extract the function from the binary */
    sprintf (tmp1, "%s.bin", prof_func[i].name);
    sprintf (tmp1, "%s.bin", prof_func[i].name);
    end_addr = extract_function (tmp1, start_addr);
    end_addr = extract_function (tmp1, start_addr);
 
 
    log ("Testing function %s (%08x - %08x)\n", prof_func[i].name, start_addr, end_addr);
    log ("Testing function %s (%08lx - %08lx)\n", prof_func[i].name, start_addr,
    PRINTF ("Testing function %s (%08x - %08x)\n", prof_func[i].name, start_addr, end_addr);
         end_addr);
 
    PRINTF ("Testing function %s (%08lx - %08lx)\n", prof_func[i].name,
 
            start_addr, end_addr);
    func[i] = analyse_function (prof_func[i].name, orig_time, start_addr,
    func[i] = analyse_function (prof_func[i].name, orig_time, start_addr,
                   end_addr, config.cuc.memory_order, prof_func[i].calls);
                   end_addr, config.cuc.memory_order, prof_func[i].calls);
    func_v[i] = 0;
    func_v[i] = 0;
  }
  }
  set_func_deps ();
  set_func_deps ();
Line 636... Line 643...
      /* profile command */
      /* profile command */
    } else if (strcmp (tmp1, "p") == 0 || strcmp (tmp1, "profile") == 0) {
    } else if (strcmp (tmp1, "p") == 0 || strcmp (tmp1, "profile") == 0) {
      int ntime = 0;
      int ntime = 0;
      int size = 0;
      int size = 0;
      PRINTF ("-----------------------------------------------------------------------------\n");
      PRINTF ("-----------------------------------------------------------------------------\n");
      PRINTF ("|function name       |calls|avg cycles  |old%| max. f.  | impr. f.| options |\n");
      PRINTF ("|function name       |calls|avg cycles  |old%%| max. f.  | impr. f.| options |\n");
      PRINTF ("|--------------------+-----+------------+----+----------|---------+---------|\n");
      PRINTF ("|--------------------+-----+------------+----+----------|---------+---------|\n");
      for (j = 0; j < prof_nfuncs; j++) {
      for (j = 0; j < prof_nfuncs; j++) {
        int bestcyc = 0, besti = 0;
        int bestcyc = 0, besti = 0;
        char tmp[100];
        char tmp[100];
        for (i = 0; i < prof_nfuncs; i++)
        for (i = 0; i < prof_nfuncs; i++)
          if (prof_func[i].cum_cycles > bestcyc) {
          if (prof_func[i].cum_cycles > bestcyc) {
            bestcyc = prof_func[i].cum_cycles;
            bestcyc = prof_func[i].cum_cycles;
            besti = i;
            besti = i;
          }
          }
        i = besti;
        i = besti;
        PRINTF ("|%-20s|%5i|%12.1f|%3.0f%%| ",
        PRINTF ("|%-20s|%5li|%12.1f|%3.0f%%| ",
                strstrip (tmp, prof_func[i].name, 20),  prof_func[i].calls,
                strstrip (tmp, prof_func[i].name, 20),  prof_func[i].calls,
                ((double)prof_func[i].cum_cycles / prof_func[i].calls),
                ((double)prof_func[i].cum_cycles / prof_func[i].calls),
                (100. * prof_func[i].cum_cycles / prof_cycles));
                (100. * prof_func[i].cum_cycles / prof_cycles));
        if (func[i]) {
        if (func[i]) {
          double f = 1.0;
          double f = 1.0;
Line 706... Line 713...
          PRINTF ("%s\n", prof_func[j].name);
          PRINTF ("%s\n", prof_func[j].name);
        }
        }
 
 
      /* selectall command */
      /* selectall command */
    } else if (strcmp (tmp1, "sa") == 0 || strcmp (tmp1, "selectall") == 0) {
    } else if (strcmp (tmp1, "sa") == 0 || strcmp (tmp1, "selectall") == 0) {
      char tmp[50], ch;
      int f;
      int p, o, b, f;
 
      for (f = 0; f < prof_nfuncs; f++) if (func[f]) {
      for (f = 0; f < prof_nfuncs; f++) if (func[f]) {
        func_v[f] = 1;
        func_v[f] = 1;
        PRINTF ("Function %s selected for translation.\n", prof_func[f].name);
        PRINTF ("Function %s selected for translation.\n", prof_func[f].name);
      }
      }
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.