Go to the documentation of this file.00001
00002
00003 #include "osl/effect_util/pin.h"
00004 #include "osl/record/csaString.h"
00005 #include "osl/record/csaRecord.h"
00006 #include "osl/misc/perfmon.h"
00007
00008 #include <iostream>
00009 #include <fstream>
00010
00011 using namespace osl;
00012 using namespace osl::effect_util;
00013
00014 void usage(const char *program_name)
00015 {
00016 std::cerr << program_name << " csafiles\n";
00017 exit(1);
00018 }
00019
00020 size_t skip_first = 0;
00021 void run(const char *filename);
00022
00023 int main(int argc, char **argv)
00024 {
00025 const char *program_name = argv[0];
00026 bool error_flag = false;
00027
00028 extern char *optarg;
00029 extern int optind;
00030 char c;
00031 while ((c = getopt(argc, argv, "s:vh")) != EOF)
00032 {
00033 switch(c)
00034 {
00035 case 's': skip_first = atoi(optarg);
00036 break;
00037 default: error_flag = true;
00038 }
00039 }
00040 argc -= optind;
00041 argv += optind;
00042
00043 if (error_flag || (argc < 1))
00044 usage(program_name);
00045
00046 try
00047 {
00048 for (int i=0; i<argc; ++i)
00049 {
00050 run(argv[i]);
00051 }
00052 }
00053 catch (std::exception& e)
00054 {
00055 std::cerr << e.what() << "\n";
00056 return 1;
00057 }
00058 catch (...)
00059 {
00060 throw;
00061 }
00062 }
00063
00064 void run(const char *filename)
00065 {
00066 unsigned long long total_cycles=0;
00067 unsigned long long total_cycles_naive=0;
00068 unsigned long long total_cycles_step=0;
00069 unsigned long long total_cycles_step1=0;
00070 unsigned long long positions = 0;
00071 Record rec=CsaFile(filename).getRecord();
00072 NumEffectState state(rec.getInitialState());
00073 const vector<osl::Move> moves=rec.getMoves();
00074
00075 size_t i=0;
00076 while (true)
00077 {
00078 if (i >= skip_first)
00079 {
00080 misc::PerfMon clock;
00081 const PieceMask black_pins = Pin::make(state, BLACK);
00082 const PieceMask white_pins = Pin::make(state, WHITE);
00083 total_cycles += clock.stop();
00084 clock.restart();
00085 const PieceMask black_pins_naive = Pin::makeNaive(state, BLACK);
00086 const PieceMask white_pins_naive = Pin::makeNaive(state, WHITE);
00087 total_cycles_naive += clock.stop();
00088 clock.restart();
00089 const PieceMask black_pins_step = Pin::makeStep(state, state.kingSquare<BLACK>(),BLACK);
00090 const PieceMask white_pins_step = Pin::makeStep(state, state.kingSquare<WHITE>(),WHITE);
00091 total_cycles_step += clock.stop();
00092 clock.restart();
00093 const PieceMask black_pins_step1 = Pin::makeStep1(state, state.kingSquare<BLACK>(),BLACK);
00094 const PieceMask white_pins_step1 = Pin::makeStep1(state, state.kingSquare<WHITE>(),WHITE);
00095 total_cycles_step1 += clock.stop();
00096 ++positions;
00097 }
00098 if (i >= moves.size())
00099 break;
00100 const Move move = moves[i++];
00101 state.makeMove(move);
00102 }
00103 std::cerr << "p " << total_cycles << " / " << positions << " = "
00104 << total_cycles/(double)positions << "\n";
00105 std::cerr << "n " << total_cycles_naive << " / " << positions << " = "
00106 << total_cycles_naive/(double)positions << "\n";
00107 std::cerr << "n " << total_cycles_step << " / " << positions << " = "
00108 << total_cycles_step/(double)positions << "\n";
00109 std::cerr << "n " << total_cycles_step1 << " / " << positions << " = "
00110 << total_cycles_step1/(double)positions << "\n";
00111 }
00112
00113
00114
00115
00116
00117