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

Subversion Repositories or2k

[/] [or2k/] [trunk/] [analysis-bin/] [insnanalysis/] [or1k-32-insn.c] - Diff between revs 24 and 25

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

Rev 24 Rev 25
Line 18... Line 18...
typedef uint32_t instruction;
typedef uint32_t instruction;
typedef struct or1k_32_instruction_properties instruction_properties ;
typedef struct or1k_32_instruction_properties instruction_properties ;
 
 
#include "insn-lists.h"
#include "insn-lists.h"
 
 
// Enable debug printf'ing straight to stdout -- will be a LOT of output
 
#define DEBUG_PRINT 0
 
 
 
// Choose the output format, uncomment only one
 
//#define DISPLAY_STRING
 
#define DISPLAY_CSV
 
 
 
 
 
// Variable to keep track of unique instructions we have
// Variable to keep track of unique instructions we have
int num_setup_insns;
int num_setup_insns;
int num_seen_insns;
int num_seen_insns;
 
 
struct or1k_insn_info * or1k_32_insns[OR1K_32_MAX_INSNS];
struct or1k_insn_info * or1k_32_insns[OR1K_32_MAX_INSNS];
Line 1005... Line 997...
// Passed binary copy of instruction, and pointer to properties struct
// Passed binary copy of instruction, and pointer to properties struct
// Each function that can collect staistics is called.
// Each function that can collect staistics is called.
void or1k_32_collect_stats(uint32_t insn,
void or1k_32_collect_stats(uint32_t insn,
                         struct or1k_32_instruction_properties  * insn_props)
                         struct or1k_32_instruction_properties  * insn_props)
{
{
  // Add this instruction's occurance to our data
  // Add this instruction's occurrence to our data
  insn_lists_add(insn, insn_props);
  insn_lists_add(insn, insn_props);
 
 
  // n-tuple groupings stats recording here!  
  // n-tuple groupings stats recording here!  
  // only if we've seen enough to do all the sequence analysis
  // only if we've seen enough to do all the sequence analysis
  if (num_seen_insns > OR1K_MAX_GROUPINGS_ANALYSIS+1)
  if (num_seen_insns > OR1K_MAX_GROUPINGS_ANALYSIS+1)
Line 1104... Line 1096...
    {
    {
      // Here we allocate space for the instruction's stats
      // Here we allocate space for the instruction's stats
      or1k_32_insn_lists_init_insn(insn, insn_props);
      or1k_32_insn_lists_init_insn(insn, insn_props);
    }
    }
 
 
  // Increment occurance count
  // Increment occurrence count
  ((or1k_32_insns[insn_props->insn_index])->count)++;
  ((or1k_32_insns[insn_props->insn_index])->count)++;
 
 
  // Add branch target value information, if instruction has it
  // Add branch target value information, if instruction has it
  if (insn_props->has_branchtarg)
  if (insn_props->has_branchtarg)
    {
    {
Line 1306... Line 1298...
  int i, largest, largest_index;
  int i, largest, largest_index;
  int instructions_to_print = num_setup_insns;
  int instructions_to_print = num_setup_insns;
 
 
#ifdef DISPLAY_CSV
#ifdef DISPLAY_CSV
  fprintf(stream,"\"Most frequent instructions, descending\",\n");
  fprintf(stream,"\"Most frequent instructions, descending\",\n");
  fprintf(stream,"\"Instruction\",\"Occurances\",\"Frequency\",\n");
  fprintf(stream,"\"Instruction\",\"Occurrences\",\"Frequency\",\n");
#endif
#endif
 
 
  while (instructions_to_print)
  while (instructions_to_print)
    {
    {
      --instructions_to_print;
      --instructions_to_print;
Line 1462... Line 1454...
  fprintf(stream,
  fprintf(stream,
#ifdef DISPLAY_STRING
#ifdef DISPLAY_STRING
          "Insn: \"%s\" statistics (%d times (%f%%))\n",
          "Insn: \"%s\" statistics (%d times (%f%%))\n",
#endif
#endif
#ifdef DISPLAY_CSV
#ifdef DISPLAY_CSV
          "\"Insn:\",\"%s\",\"occurances:\",%d,%f\n",
          "\"Instruction:\",\"%s\",\"occurrences:\",%d,%f\n",
#endif
#endif
          insn_info->insn_string,
          insn_info->insn_string,
          insn_info->count,
          insn_info->count,
          (float)(((float)((insn_info)->count))/
          (float)(((float)((insn_info)->count))/
                  ((float)num_seen_insns))*100.f
                  ((float)num_seen_insns))*100.f
Line 1482... Line 1474...
      fprintf(stream,
      fprintf(stream,
#ifdef DISPLAY_STRING
#ifdef DISPLAY_STRING
              "Branch values:\n"
              "Branch values:\n"
#endif
#endif
#ifdef DISPLAY_CSV
#ifdef DISPLAY_CSV
              "\"branch distance\",\"occurances\"\n"
              "\"branch distance\",\"occurrences\"\n"
#endif
#endif
              );
              );
      i = 0;
      i = 0;
      while(i<insn_info->branch_info.count && i < max_stats)
      while(i<insn_info->branch_info.count && i < max_stats)
        {
        {
Line 1745... Line 1737...
      largest_indx = 0;
      largest_indx = 0;
      for(set_count2=0;set_count2<total_sets_for_ntuple;set_count2++)
      for(set_count2=0;set_count2<total_sets_for_ntuple;set_count2++)
        largest_indx = (set_count_copy[set_count2 + 1] >
        largest_indx = (set_count_copy[set_count2 + 1] >
                        set_count_copy[largest_indx + 1]) ?
                        set_count_copy[largest_indx + 1]) ?
          set_count2 : largest_indx;
          set_count2 : largest_indx;
      // largest_indx is the index of the set with the highest occurance, so
      // largest_indx is the index of the set with the highest occurrence, so
      // let's print it out, but first get a pointer to the set's data
      // let's print it out, but first get a pointer to the set's data
      set = (int*)ntuplelist[largest_indx+1];
      set = (int*)ntuplelist[largest_indx+1];
 
 
      // Print out the sequence of prior isntructions
      // Print out the sequence of prior isntructions
#ifdef DISPLAY_STRING
#ifdef DISPLAY_STRING
Line 1765... Line 1757...
#ifdef DISPLAY_CSV
#ifdef DISPLAY_CSV
                "\"%s\",",
                "\"%s\",",
#endif
#endif
                or1k_32_insns[(set[set_count2])]->insn_string);
                or1k_32_insns[(set[set_count2])]->insn_string);
 
 
      // now print out the occurances
      // now print out the occurrences
      fprintf(stream,
      fprintf(stream,
#ifdef DISPLAY_STRING
#ifdef DISPLAY_STRING
              "\t%d\ttimes (%f%%)\n",
              "\t%d\ttimes (%f%%)\n",
#endif
#endif
#ifdef DISPLAY_CSV
#ifdef DISPLAY_CSV
Line 1813... Line 1805...
  int insn_index;
  int insn_index;
  for(insn_index=0;insn_index<OR1K_32_MAX_INSNS;insn_index++)
  for(insn_index=0;insn_index<OR1K_32_MAX_INSNS;insn_index++)
    {
    {
      if (or1k_32_insns[insn_index] != NULL)
      if (or1k_32_insns[insn_index] != NULL)
        {
        {
          or1k_32_insn_top_n(or1k_32_insns[insn_index],stream,10);
 
          or1k_32_generate_groupings_stats(or1k_32_insns[insn_index],stream);
 
#ifdef DISPLAY_STRING
#ifdef DISPLAY_STRING
          fprintf(stream, "\t---\t---\t---\t---\n");
          fprintf(stream, "\t---\t---\t---\t---\n");
#endif
#endif
 
#ifdef DISPLAY_CSV
 
          fprintf(stream, ",\n");
 
#endif
 
          or1k_32_insn_top_n(or1k_32_insns[insn_index],stream,10);
 
          or1k_32_generate_groupings_stats(or1k_32_insns[insn_index],stream);
 
 
        }
        }
    }
    }
 
 
 
#ifdef DISPLAY_STRING
 
          fprintf(stream, "\t---\t---\t---\t---\n");
 
#endif
 
#ifdef DISPLAY_CSV
 
          fprintf(stream, ",\n");
 
#endif
 
 
 
 
  // print out most frequent n-tuple
  // print out most frequent n-tuple
  int ntuple;
  int ntuple;
  for(ntuple=2;ntuple<5;ntuple++)
  for(ntuple=2;ntuple<5;ntuple++)
    or1k_32_most_freq_ntuple(ntuple, stream, 10);
    or1k_32_most_freq_ntuple(ntuple, stream, 10);
 
 
 
 
 
#ifdef DISPLAY_STRING
 
          fprintf(stream, "\t---\t---\t---\t---\n");
 
#endif
 
#ifdef DISPLAY_CSV
 
          fprintf(stream, ",\n");
 
#endif
 
 
 
 
  // Do most frequent instruction analysis -- note this trashes instruction
  // Do most frequent instruction analysis -- note this trashes instruction
  // frequency count - should be fixed
  // frequency count - should be fixed
#ifdef DISPLAY_STRING
#ifdef DISPLAY_STRING
  fprintf(stream, "Individual instruction frequency:\n");
  fprintf(stream, "Individual instruction frequency:\n");
#endif
#endif

powered by: WebSVN 2.1.0

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