// $Id: benchmark.c 138 2010-05-12 17:34:01Z rosiere $

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#ifndef SPECINT2000_PATH
# error "SPECINT2000_PATH must be defined"
#endif

#if !defined(SPECINT2000_TEST) && !defined(SPECINT2000_TRAIN) && !defined(SPECINT2000_REF)
# error "SPECINT2000_TEST, SPECINT2000_TRAIN or SPECINT2000_REF must be defined"
#endif

#if defined(SPECINT2000_TEST)
# error "SPECINT2000_TEST not yet supported"
#endif

#if defined(SPECINT2000_REF)
# error "SPECINT2000_REF not yet supported"
#endif

#ifdef SPEC_gzip
int main_164_gzip   (int argc, char * argv[]);
#endif
#ifdef SPEC_vpr
int main_175_vpr    (int argc, char * argv[]);
#endif
#ifdef SPEC_gcc
int main_176_gcc    (int argc, char * argv[]);
#endif
#ifdef SPEC_mcf
int main_181_mcf    (int argc, char * argv[]);
#endif
#ifdef SPEC_vortex
int main_255_vortex (int argc, char * argv[]);
#endif
#ifdef SPEC_bzip
int main_256_bzip2  (int argc, char * argv[]);
#endif
#ifdef SPEC_twolf
int main_300_twolf  (int argc, char * argv[]);
#endif

//=======================================================================================
//                                                                      [ run_none ]     
//=======================================================================================
void run_none ()
{
  printf("***** none *****\n");
  return;
}

//=======================================================================================
//                                                                  [ run_164_gzip ]
//=======================================================================================
#ifdef SPECINT2000_TRAIN
void main_164_gzip_train ()
{
#ifdef SPEC_gzip
  int     argc = 4;
  char ** argv;

  char  * execname        = "./gzip";
  char  *_filename        = "/164.gzip/data/test/input/input.compressed";
  char  * filename        = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_filename));
  strcpy(filename,SPECINT2000_PATH); strcat(filename,_filename);
  char  * input_size      = "1";
  char  * compressed_size = "1";

 // Create the arguments
  if ((argc < 1) || (argc > 4) )
    {
      printf("Usage : gzip [filename] [intput_size] [compressed_size]\n");
      return;
    }
    
  argv    = (char **)malloc (argc * sizeof(char *));
  
  argv[0] = (char *) malloc (strlen(execname       ));
  argv[0] = memcpy(argv[0],execname        ,strlen(execname       ));

  if (argc > 1)
    {
  argv[1] = (char *) malloc (strlen(filename       ));
  argv[1] = memcpy(argv[1],filename        ,strlen(filename       ));
    }
  
  if (argc > 2)
    {
  argv[2] = (char *) malloc (strlen(input_size     ));
  argv[2] = memcpy(argv[2],input_size      ,strlen(input_size     ));
    }

  if (argc > 3)
    {  
  argv[3] = (char *) malloc (strlen(compressed_size));
  argv[3] = memcpy(argv[3],compressed_size ,strlen(compressed_size));
    }

  // +-------------------+
  // | Run the benchmark |
  // +-------------------+
  main_164_gzip (argc,argv);

  free(filename);
#endif
}
#endif

void run_164_gzip ()
{
  printf("***** 164.gzip - Begin *****\n");

#ifdef SPECINT2000_TRAIN
  main_164_gzip_train ();
#endif

  printf("***** 164.gzip - End   *****\n");
}

//=======================================================================================
//                                                                   [ run_175_vpr ]
//=======================================================================================

#ifdef SPECINT2000_TRAIN
void main_175_vpr_train ()
{
#ifdef SPEC_vpr

#define   nb_option_175_vpr 12
  int     argc      = 5 + nb_option_175_vpr;
  char ** argv;

  char  * execname        = "./vpr";
       
  char  *_circuit_net     = "/175.vpr/data/test/input/net.in";
  char  *_fpga_arch       = "/175.vpr/data/test/input/arch.in";
  char  *_placed_out      = "/175.vpr/data/test/input/place.in";
  char  *_routed_out      = "/175.vpr/data/test/input/route.out";
       
  char  * circuit_net     = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_circuit_net));
  char  * fpga_arch       = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_fpga_arch  ));
  char  * placed_out      = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_placed_out ));
  char  * routed_out      = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_routed_out ));

  strcpy(circuit_net,SPECINT2000_PATH); strcat(circuit_net,_circuit_net);
  strcpy(fpga_arch  ,SPECINT2000_PATH); strcat(fpga_arch  ,_fpga_arch  );
  strcpy(placed_out ,SPECINT2000_PATH); strcat(placed_out ,_placed_out );
  strcpy(routed_out ,SPECINT2000_PATH); strcat(routed_out ,_routed_out );

  /*
  General Options:  
  [-nodisp]
  [-auto <int>]
  [-route_only]
  [-place_only]
  [-aspect_ratio <float>]
  [-nx <int>]
  [-ny <int>]
  [-full_stats]
  [-fast]
  [-timing_analysis on | off]

  Placer Options:
  [-init_t <float>]
  [-exit_t <float>]
  [-alpha_t <float>]
  [-inner_num <float>]
  [-seed <int>]
  [-place_cost_exp <float>]
  [-place_cost_type linear | nonlinear]
  [-place_chan_width <int>]
  [-num_regions <int>]
  [-fix_pins random | <file.pads>]
  
  Router Options:  
  [-max_router_iterations <int>]
  [-bb_factor <int>]
  [-initial_pres_fac <float>]
  [-pres_fac_mult <float>]
  [-acc_fac <float>]
  [-first_iter_pres_fac <float>]
  [-bend_cost <float>]
  [-route_type global | detailed]
  [-verify_binary_search]
  [-route_chan_width <int>]
  */

  char * option [nb_option_175_vpr] = 
    {
      "-nodisp"              ,
      "-route_only"          , 
      "-route_chan_width"    , "15",
      "-pres_fac_mult"       , "2" ,
      "-acc_fac"             , "1" ,
      "-first_iter_pres_fac" , "4" ,
      "-initial_pres_fac"    , "8" 
    };
  
  // Create the arguments
  if (argc < 5)
    {
      printf("Usage : vpr circuit.net fpga.arch placed.out routed.out [Options ...]\n");
      return;
    }
    
  argv    = (char **)malloc (argc * sizeof(char *));
  
  argv[0] = (char *) malloc (strlen(execname       ));
  argv[0] = memcpy(argv[0],execname        ,strlen(execname       ));

  argv[1] = (char *) malloc (strlen(circuit_net    ));
  argv[1] = memcpy(argv[1],circuit_net     ,strlen(circuit_net    ));

  argv[2] = (char *) malloc (strlen(fpga_arch      ));
  argv[2] = memcpy(argv[2],fpga_arch       ,strlen(fpga_arch      ));

  argv[3] = (char *) malloc (strlen(placed_out     ));
  argv[3] = memcpy(argv[3],placed_out      ,strlen(placed_out     ));

  argv[4] = (char *) malloc (strlen(routed_out     ));
  argv[4] = memcpy(argv[4],routed_out      ,strlen(routed_out     ));
  
  {
    unsigned int i;
    
    for (i = 0; i < nb_option_175_vpr; i ++)
      {
	argv[5+i] = (char *) malloc (strlen(option[i]      ));
	argv[5+i] = memcpy(argv[5+i],option[i]       ,strlen(option[i]      ));
      }// end i
  }
  
  // +-------------------+
  // | Run the benchmark |
  // +-------------------+
  main_175_vpr (argc,argv);

  free(circuit_net);
  free(fpga_arch  );
  free(placed_out );
  free(routed_out );

#endif
}
#endif

void run_175_vpr ()
{
  printf("***** 175.vpr - Begin *****\n");

#ifdef SPECINT2000_TRAIN
  main_175_vpr_train ();
#endif

  printf("***** 175.vpr - End   *****\n");
}

//=======================================================================================
//                                                                   [ run_176_gcc ]
//=======================================================================================
#ifdef SPECINT2000_TRAIN
void main_176_gcc_train ()
{
#ifdef SPEC_gcc

#define   nb_option_176_gcc 2
  int     argc      = 2 + nb_option_176_gcc;
  char ** argv;

  char  * execname        = "./gcc";
  char  *_filename        = "/176.gcc/data/test/input/cccp.i";
  char  * filename        = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_filename));
  strcpy(filename,SPECINT2000_PATH); strcat(filename,_filename);

  /*
    -O
    -fdefer-pop
    -fomit-frame-pointer
    -fcse-follow-jumps
    -fcse-skip-blocks
    -fexpensive-optimizations
    -fthread-jumps
    -fstrength-reduce
    -funroll-loops
    -fwritable-strings
    -fpeephole
    -fforce-mem
    -ffunction-cse
    -finline-functions
    -finline
    -freg-struct-return
    -fdelayed-branch
    -frerun-cse-after-loop
    -fschedule-insns
    -fschedule-insns2
    -fcommon
    -fgnu-linker
    -m88110
    -m88100
    -m88000
    -mno-ocs-debug-info
    -mno-ocs-frame-position
    -mcheck-zero-division
  */

  char * option [nb_option_176_gcc] = 
    {
      "-o"                   , "cccp.s"
    };
  
  // Create the arguments
  if (argc < 2)
    {
      printf("Usage : gcc filename [Options ...]\n");
      return;
    }
    
  argv    = (char **)malloc (argc * sizeof(char *));
  
  argv[0] = (char *) malloc (strlen(execname       ));
  argv[0] = memcpy(argv[0],execname        ,strlen(execname       ));
  argv[1] = (char *) malloc (strlen(filename       ));
  argv[1] = memcpy(argv[1],filename        ,strlen(filename       ));
  
  {
    unsigned int i;
    
    for (i = 0; i < nb_option_176_gcc; i ++)
      {
	argv[2+i] = (char *) malloc (strlen(option[i]      ));
	argv[2+i] = memcpy(argv[2+i],option[i]       ,strlen(option[i]      ));
      }// end i
  }
  
  // +-------------------+
  // | Run the benchmark |
  // +-------------------+
  main_176_gcc (argc,argv);

  free(filename);
  
#endif
}
#endif
                     
void run_176_gcc ()
{
  printf("***** 176.gcc - Begin *****\n");

#ifdef SPECINT2000_TRAIN
  main_176_gcc_train ();
#endif

  printf("***** 176.gcc - End   *****\n");
}


//=======================================================================================
//                                                                   [ run_181_mcf ]
//=======================================================================================
#ifdef SPECINT2000_TRAIN
void main_181_mcf_train ()
{
#ifdef SPEC_mcf
  
  int     argc = 2;
  char ** argv;

  char  * execname        = "./mcf";
  char  *_filename        = "/181.mcf/data/test/input/inp.in";
  char  * filename        = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_filename));
  strcpy(filename,SPECINT2000_PATH); strcat(filename,_filename);

  // Create the arguments
  if (argc != 2)
    {
      printf("Usage : mcf filename\n");
      return;
    }
    
  argv    = (char **)malloc (argc * sizeof(char *));
  
  argv[0] = (char *) malloc (strlen(execname       ));
  argv[0] = memcpy(argv[0],execname        ,strlen(execname       ));

  argv[1] = (char *) malloc (strlen(filename       ));
  argv[1] = memcpy(argv[1],filename        ,strlen(filename       ));
  
  // +-------------------+
  // | Run the benchmark |
  // +-------------------+
  main_181_mcf (argc,argv);

  free(filename);
  
#endif
}
#endif

void run_181_mcf ()
{
  printf("***** 181.mcf - Begin *****\n");

#ifdef SPECINT2000_TRAIN
  main_181_mcf_train ();
#endif

  printf("***** 181.mcf - End   *****\n");
}

//=======================================================================================
//                                                                [ run_255_vortex ]
//=======================================================================================
#ifdef SPECINT2000_TRAIN
void main_255_vortex_train ()
{
#ifdef SPEC_vortex
  
  int     argc = 2;
  char ** argv;

  char  * execname        = "./vortex";
#if defined(MORPHEO)
  char  *_filename        = "/255.vortex/data/test/input/bendian.raw";
#else
# if (defined(EV67) || defined(x86))
  char  *_filename        = "/255.vortex/data/test/input/lendian.raw";
# else
#  error "Unknow target"
# endif
#endif

  char  * filename        = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_filename));
  strcpy(filename,SPECINT2000_PATH); strcat(filename,_filename);
  
  // Create the arguments
  if (argc != 2)
    {
      printf("Usage : vortex filename\n");
      return;
    }
    
  argv    = (char **)malloc (argc * sizeof(char *));

  argv[0] = (char *) malloc (strlen(execname       ));
  argv[0] = memcpy(argv[0],execname        ,strlen(execname       ));
  argv[1] = (char *) malloc (strlen(filename       ));
  argv[1] = memcpy(argv[1],filename        ,strlen(filename       ));

  // +-------------------+
  // | Run the benchmark |
  // +-------------------+
  main_255_vortex (argc,argv);

  free(filename);
  
#endif
}
#endif

void run_255_vortex ()
{
  printf("***** 255.vortex - Begin *****\n");

#ifdef SPECINT2000_TRAIN
  main_255_vortex_train ();
#endif

  printf("***** 255.vortex - End   *****\n");
}
 
//=======================================================================================
//                                                                 [ run_256_bzip2 ]
//=======================================================================================
#ifdef SPECINT2000_TRAIN
void main_256_bzip2_train ()
{
#ifdef SPEC_bzip

  int     argc = 4;
  char ** argv;

  char  * execname        = "./bzip2";
  char  *_filename        = "/256.bzip2/data/test/input/input.random";
  char  * filename        = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_filename));
  strcpy(filename,SPECINT2000_PATH); strcat(filename,_filename);
  char  * input_size      = "1";
  char  * compressed_size = "1";

  // Create the arguments
  if ((argc < 1) || (argc > 4) )
    {
      printf("Usage : bzip2 [filename] [intput_size] [compressed_size]\n");
      return;
    }
  
  argv    = (char **)malloc (argc * sizeof(char *));
  argv[0] = (char *) malloc (strlen(execname       ));
  argv[0] = memcpy(argv[0],execname        ,strlen(execname       ));

  if (argc > 1)
    {
  argv[1] = (char *) malloc (strlen(filename       ));
  argv[1] = memcpy(argv[1],filename        ,strlen(filename       ));
    }
  
  if (argc > 2)
    {
  argv[2] = (char *) malloc (strlen(input_size     ));
  argv[2] = memcpy(argv[2],input_size      ,strlen(input_size     ));
    }

  if (argc > 3)
    {  
  argv[3] = (char *) malloc (strlen(compressed_size));
  argv[3] = memcpy(argv[3],compressed_size ,strlen(compressed_size));
    }
  
  // +-------------------+
  // | Run the benchmark |
  // +-------------------+
  main_256_bzip2 (argc,argv);

  free(filename);
  
#endif
}
#endif

void run_256_bzip2 ()
{
  printf("***** 256.bzip2 - Begin *****\n");

#ifdef SPECINT2000_TRAIN
  main_256_bzip2_train ();
#endif

  printf("***** 256.bzip2 - End   *****\n");
}

//=======================================================================================
//                                                                 [ run_300_twolf ]
//=======================================================================================
#ifdef SPECINT2000_TRAIN
void main_300_twolf_train ()
{
#ifdef SPEC_twolf

  int     argc = 2;
  char ** argv;

  char  * execname        = "./twolf";
  char  *_circuitName     = "/300.twolf/data/test/input/test";
  char  * circuitName     = (char *) malloc(strlen(SPECINT2000_PATH)+strlen(_circuitName));
  strcpy(circuitName,SPECINT2000_PATH); strcat(circuitName,_circuitName);

  // Create the arguments
  if ((argc < 1) || (argc > 2) )
    {
      printf("Usage : twolf circuitName\n");
      return;
    }
  
  argv    = (char **)malloc (argc * sizeof(char *));
  argv[0] = (char *) malloc (strlen(execname       ));
  argv[0] = memcpy(argv[0],execname        ,strlen(execname       ));

  argv[1] = (char *) malloc (strlen(circuitName       ));
  argv[1] = memcpy(argv[1],circuitName     ,strlen(circuitName    ));
  
  // +-------------------+
  // | Run the benchmark |
  // +-------------------+
  main_300_twolf (2,argv);

  free(circuitName);
  
#endif
}
#endif

void run_300_twolf ()
{
  printf("***** 300.twolf - Begin *****\n");

#ifdef SPECINT2000_TRAIN
  main_300_twolf_train ();
#endif

  printf("***** 300.twolf - End   *****\n");
}
