inline int stoptimer(){
    timerstop = readtsc();
}
예제 #2
0
파일: test.cpp 프로젝트: gpiez/hayabusa
void TestRootBoard::generateCaptures() {
    QTextStream xout(stderr);
    cpu_set_t mask;
    CPU_ZERO( &mask );
    CPU_SET( 1, &mask );
    if ( sched_setaffinity( 0, sizeof(mask), &mask ) == -1 )
        qDebug() << "Could not set CPU Affinity" << endl;
    static const unsigned testCases = 200;
    static const int iter = 10000;
    typedef QVector<uint64_t> Sample;
    QVector<Sample> times(testCases, Sample(iter));
    QVector<Sample> movetimes(testCases, Sample(iter));
    QVector<Sample> captimes(testCases, Sample(iter));
    QVector<Sample> b02flood(testCases, Sample(iter));
    QVector<Sample> b02point(testCases, Sample(iter));
    QVector<Sample> b02double(testCases, Sample(iter));
    Move moveList[256];
    uint64_t sum=0;
    uint64_t movesum=0;
    uint64_t nmoves=0;
    uint64_t ncap =0;
    uint64_t a, d, tsc;
    Key blah;
    Colors color[testCases];
    double cpufreq = 3900.0;
    for (unsigned int i = testCases; i;) {
        --i;
        b->setup(testPositions[i]);
        color[i] = b->color;
        if (i) {
            b->boards[i] = b->boards[0]; }
        movetimes[i].reserve(iter*2);
        times[i].reserve(iter*2);
        captimes[i].reserve(iter*2); }
    unsigned op = 1;
    const unsigned int iter2 = 10000000;
    __v2di res = _mm_set1_epi64x(0);
    uint64_t time=0;
#ifdef NDEBUG
    for (unsigned int i = 0; i < iter2; ++i) {
        Board& bb = b->boards[i & 0xf].wb;
        tsc = readtsc();
        res = bb.build02Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build02Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build02Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build02Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build02Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build02Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build02Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build02Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        time += readtsc() - tsc;
//        op = fold(res) & 0x3f;
    }
    std::cout << "build02(pos): " << time/iter2 << " clocks" << std::endl;

    time=0;
    for (unsigned int i = 0; i < iter2; ++i) {
        Board& bb = b->boards[i & 0xf].wb;
        tsc = readtsc();
        res = bb.build13Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build13Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build13Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build13Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build13Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build13Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build13Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        res = bb.build13Attack(op);
        op = _mm_cvtsi128_si64(res) & 0x3f;
        time += readtsc() - tsc; }
    std::cout << "build13(pos): " << time/iter2 << " clocks" << std::endl;

//     time=0;
//     for (unsigned int i = 0; i < iter2; ++i) {
//         BoardBase& bb = b->boards[i & 0xf].wb;
//         tsc = readtsc();
//         res = bb.build02Attack(res);
//         time += readtsc() - tsc;
//     }
//     std::cout << "build02(vector): " << time/iter2 << " clocks" << std::endl;

    time=0;
    for (unsigned int i = 0; i < iter2; ++i) {
        Board& bb = b->boards[i & 0xf].wb;
        tsc = readtsc();
        res = b->boards[0].wb.build13Attack(res);
        res = b->boards[1].wb.build13Attack(res);
        res = b->boards[2].wb.build13Attack(res);
        res = b->boards[3].wb.build13Attack(res);
        res = b->boards[4].wb.build13Attack(res);
        res = b->boards[5].wb.build13Attack(res);
        res = b->boards[6].wb.build13Attack(res);
        res = b->boards[7].wb.build13Attack(res);
        time += readtsc() - tsc; }
    std::cout << "build13(vector): " << time/iter2 << " clocks" << std::endl;

    for (int j = 0; j < iter; ++j) {
        nmoves = 0;
        ncap=0;
        for (unsigned int i = 0; i < testCases; ++i) {
//                      b->setup(testPositions[i]);
            uint64_t  overhead;
            /*
             asm volatile("cpuid\n rdtsc" : "=a" (a), "=d" (d) :: "%rbx", "%rcx");
             tsc = (a + (d << 32));
             asm volatile("cpuid\n rdtsc" : "=a" (a), "=d" (d) :: "%rbx", "%rcx");
             overhead = (a + (d << 32)) - tsc;
             */
            overhead = 20;
            if (color[i] == White)
                b->boards[i].wb.buildAttacks();
            else
                b->boards[i].bb.buildAttacks();

            tsc = readtsc();
            Move* good = moveList+192;
            Move* bad = good;
            if (color[i] == White)
                b->boards[i].wb.generateCaptureMoves<AllMoves>(good, bad);
            else
                b->boards[i].bb.generateCaptureMoves<AllMoves>(good, bad);
            ncap += bad - good;
            captimes[i][j] = readtsc() - tsc - overhead;

            tsc = readtsc();
            if (color[i] == White)
                b->boards[i].wb.generateNonCap(good, bad);
            else
                b->boards[i].bb.generateNonCap(good, bad);
            nmoves += bad - good;
            times[i][j] = readtsc() - tsc - overhead;
            for (Move* k=good; k<bad; ++k) {
//                              std::cout << k->string() << std::endl;
                tsc = readtsc();
                if (color[i] == White) {
                    __v8hi est = b->boards[i].b->eval.estimate(wb, *k);
                    ColoredBoard<Black> bb(b->boards[i].wb, *k, est);
                    blah += bb.getZobrist(); }
                else {
                    __v8hi est = b->boards[i].b->eval.estimate(bb, *k);
                    ColoredBoard<White> bb(b->boards[i].bb, *k, est);
                    blah += bb.getZobrist(); }
                movetimes[i][j] += readtsc() - tsc - overhead; }
//                      std::string empty;
//                      std::cin >> empty;
        } }
    for (QVector<Sample>::Iterator i = times.begin(); i != times.end(); ++i) {
        qSort(*i);
        sum += (*i)[iter / 2]; }
    uint64_t capsum=0;
    for (QVector<Sample>::Iterator i = captimes.begin(); i != captimes.end(); ++i) {
        qSort(*i);
        capsum += (*i)[iter / 2]; }
    for (QVector<Sample>::Iterator i = movetimes.begin(); i != movetimes.end(); ++i) {
        qSort(*i);
        movesum += (*i)[iter / 2]; }

    xout << endl << nmoves << " Moves, " << sum/nmoves << " Clocks, " << cpufreq* nmoves/sum << " generated Mmoves/s, " << cpufreq* nmoves/movesum << " executed Mmoves/s" << endl;
    xout << ncap << " Captures, " << capsum/ncap << " Clocks, " << cpufreq* ncap/capsum << " generated Mmoves/s, " /*<< cpufreq*ncap/movesum << " executed Mmoves/s" */<< endl;
    xout << blah + fold(res) + op64 << endl;
#endif

}
inline int starttimer(){
    timerstart = readtsc();
}