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