Esempio n. 1
0
int main(int argc, char *argv[])
{
    int mode = SDL_HWSURFACE | SDL_HWACCEL |
        SDL_DOUBLEBUF | SDL_OPENGL;

    if (argc >= 2 && (! strcmp(argv[1], "-h") ||
                      ! strcmp(argv[1], "--help"))) {
        printf("Uso: %s [-fs] resolucao-x resolucao-y\n\n"
               "Exemplo: ./walker 1024 768\n\n"
               "Para mais informacoes, leia o README.\n",
               argv[0]);
        exit(0);
    }

    int shift = 1;
    if (argc >= 2 && ! strcmp(argv[1], "-fs")) {
        mode |= SDL_FULLSCREEN;
        res_x = 1360;
        res_y = 768;
        shift++;
    }
    if (argc >= 3) {
        res_x = atoi(argv[shift]);
        res_y = atoi(argv[shift+1]);
    }

    init_event_keys();

    glutInit(&argc, argv);
    initsdl(mode);
    initgl();

    carregar_texturas();

    SDL_Event ev;

    while (1)
        if (! SDL_PollEvent(&ev)
            || ev.type == SDL_MOUSEMOTION)
            break;
        else
            event_handler(ev);

    uint64_t old_time, new_time;
    uint64_t old_border, new_border;
    old_time = time_get();
    old_border = time_in_secs(old_time);

    float dt = 0;
    int count = 0;

    while (1) {
        while (SDL_PollEvent(&ev))
            event_handler(ev);

        new_time = time_get();
        new_border = time_in_secs(new_time);

        dt = time_diff(new_time, old_time);

        if (new_border > old_border) {
            update_fps_str(count);
            old_border = new_border;
            count = 0;
        }

        old_time = new_time;
        count++;

        update_status_str();

        toggle();
        model(dt);
        physics(dt);
        update_map_pos();
        draw();
    }
}
Esempio n. 2
0
MAIN_RETURN_TYPE main(void) {
    int argc=0;
    char *argv[1];
#else
MAIN_RETURN_TYPE main(int argc, char *argv[]) {
#endif
    ee_u16 i,j=0,num_algorithms=0;
    ee_s16 known_id=-1,total_errors=0;
    ee_u16 seedcrc=0;
    CORE_TICKS total_time;
    core_results results[MULTITHREAD];
#if (MEM_METHOD==MEM_STACK)
    ee_u8 stack_memblock[TOTAL_DATA_SIZE*MULTITHREAD];
#endif
    /* first call any initializations needed */
    portable_init(&(results[0].port), &argc, argv);
    /* First some checks to make sure benchmark will run ok */
    if (sizeof(struct list_head_s)>128) {
        printstr("list_head structure too big for comparable data!\n");
        return MAIN_RETURN_VAL;
    }
    results[0].seed1=get_seed(1);
    results[0].seed2=get_seed(2);
    results[0].seed3=get_seed(3);
    results[0].iterations=get_seed_32(4);
#if CORE_DEBUG
    results[0].iterations=1;
#endif
    results[0].execs=get_seed_32(5);
    if (results[0].execs==0) { /* if not supplied, execute all algorithms */
        results[0].execs=ALL_ALGORITHMS_MASK;
    }
        /* put in some default values based on one seed only for easy testing */
    if ((results[0].seed1==0) && (results[0].seed2==0) && (results[0].seed3==0)) { /* validation run */
        results[0].seed1=0;
        results[0].seed2=0;
        results[0].seed3=0x66;
    }
    if ((results[0].seed1==1) && (results[0].seed2==0) && (results[0].seed3==0)) { /* perfromance run */
        results[0].seed1=0x3415;
        results[0].seed2=0x3415;
        results[0].seed3=0x66;
    }
#if (MEM_METHOD==MEM_STATIC)
    results[0].memblock[0]=(void *)static_memblk;
    results[0].size=TOTAL_DATA_SIZE;
    results[0].err=0;
    #if (MULTITHREAD>1)
    #error "Cannot use a static data area with multiple contexts!"
    #endif
#elif (MEM_METHOD==MEM_MALLOC)
    for (i=0 ; i<MULTITHREAD; i++) {
        ee_s32 malloc_override=get_seed(7);
        if (malloc_override != 0)
            results[i].size=malloc_override;
        else
            results[i].size=TOTAL_DATA_SIZE;
        results[i].memblock[0]=portable_malloc(results[i].size);
        results[i].seed1=results[0].seed1;
        results[i].seed2=results[0].seed2;
        results[i].seed3=results[0].seed3;
        results[i].err=0;
        results[i].execs=results[0].execs;
    }
#elif (MEM_METHOD==MEM_STACK)
    for (i=0 ; i<MULTITHREAD; i++) {
        results[i].memblock[0]=stack_memblock+i*TOTAL_DATA_SIZE;
        results[i].size=TOTAL_DATA_SIZE;
        results[i].seed1=results[0].seed1;
        results[i].seed2=results[0].seed2;
        results[i].seed3=results[0].seed3;
        results[i].err=0;
        results[i].execs=results[0].execs;
    }
#else
#error "Please define a way to initialize a memory block."
#endif
    /* Data init */
    /* Find out how space much we have based on number of algorithms */
    for (i=0; i<NUM_ALGORITHMS; i++) {
        if ((1<<(ee_u32)i) & results[0].execs)
            num_algorithms++;
    }
    for (i=0 ; i<MULTITHREAD; i++)
        results[i].size=results[i].size/num_algorithms;
    /* Assign pointers */
    for (i=0; i<NUM_ALGORITHMS; i++) {
        ee_u32 ctx;
        if ((1<<(ee_u32)i) & results[0].execs) {
            for (ctx=0 ; ctx<MULTITHREAD; ctx++)
                results[ctx].memblock[i+1]=(char *)(results[ctx].memblock[0])+results[0].size*j;
            j++;
        }
    }
    /* call inits */
    for (i=0 ; i<MULTITHREAD; i++) {
        if (results[i].execs & ID_LIST) {
            results[i].list=core_list_init(results[0].size,results[i].memblock[1],results[i].seed1);
        }
        if (results[i].execs & ID_MATRIX) {
            core_init_matrix(results[0].size, results[i].memblock[2], (ee_s32)results[i].seed1 | (((ee_s32)results[i].seed2) << 16), &(results[i].mat) );
        }
        if (results[i].execs & ID_STATE) {
            core_init_state(results[0].size,results[i].seed1,results[i].memblock[3]);
        }
    }

    /* automatically determine number of iterations if not set */
    if (results[0].iterations==0) {
        secs_ret secs_passed=0;
        ee_u32 divisor;
        results[0].iterations=1;
        while (secs_passed < (secs_ret)1) {
            results[0].iterations*=10;
            start_time();
            iterate(&results[0]);
            stop_time();
            secs_passed=time_in_secs(get_time());
        }
        /* now we know it executes for at least 1 sec, set actual run time at about 10 secs */
        divisor=(ee_u32)secs_passed;
        if (divisor==0) /* some machines cast float to int as 0 since this conversion is not defined by ANSI, but we know at least one second passed */
            divisor=1;
        results[0].iterations*=1+10/divisor;
    }
    /* perform actual benchmark */
    start_time();
#if (MULTITHREAD>1)
    if (default_num_contexts>MULTITHREAD) {
        default_num_contexts=MULTITHREAD;
    }
    for (i=0 ; i<default_num_contexts; i++) {
        results[i].iterations=results[0].iterations;
        results[i].execs=results[0].execs;
        core_start_parallel(&results[i]);
    }
    for (i=0 ; i<default_num_contexts; i++) {
        core_stop_parallel(&results[i]);
    }
#else
    iterate(&results[0]);
#endif
    stop_time();
    total_time=get_time();
    /* get a function of the input to report */
    seedcrc=crc16(results[0].seed1,seedcrc);
    seedcrc=crc16(results[0].seed2,seedcrc);
    seedcrc=crc16(results[0].seed3,seedcrc);
    seedcrc=crc16(results[0].size,seedcrc);

    switch (seedcrc) { /* test known output for common seeds */
        case 0x8a02: /* seed1=0, seed2=0, seed3=0x66, size 2000 per algorithm */
            known_id=0;
            printstr("6k performance run parameters for coremark.\n");
            break;
        case 0x7b05: /*  seed1=0x3415, seed2=0x3415, seed3=0x66, size 2000 per algorithm */
            known_id=1;
            printstr("6k validation run parameters for coremark.\n");
            break;
        case 0x4eaf: /* seed1=0x8, seed2=0x8, seed3=0x8, size 400 per algorithm */
            known_id=2;
            printstr("Profile generation run parameters for coremark.\n");
            break;
        case 0xe9f5: /* seed1=0, seed2=0, seed3=0x66, size 666 per algorithm */
            known_id=3;
            printstr("2K performance run parameters for coremark.\n");
            break;
        case 0x18f2: /*  seed1=0x3415, seed2=0x3415, seed3=0x66, size 666 per algorithm */
            known_id=4;
            printstr("2K validation run parameters for coremark.\n");
            break;
        default:
            total_errors=-1;
            break;
    }
    if (known_id>=0) {
        for (i=0 ; i<default_num_contexts; i++) {
            results[i].err=0;
            if ((results[i].execs & ID_LIST) &&
                (results[i].crclist!=list_known_crc[known_id])) {
                printf("[%u]ERROR! list crc 0x%04x - should be 0x%04x\n",i,results[i].crclist,list_known_crc[known_id]);
                results[i].err++;
            }
            if ((results[i].execs & ID_MATRIX) &&
                (results[i].crcmatrix!=matrix_known_crc[known_id])) {
                printf("[%u]ERROR! matrix crc 0x%04x - should be 0x%04x\n",i,results[i].crcmatrix,matrix_known_crc[known_id]);
                results[i].err++;
            }
            if ((results[i].execs & ID_STATE) &&
                (results[i].crcstate!=state_known_crc[known_id])) {
                printf("[%u]ERROR! state crc 0x%04x - should be 0x%04x\n",i,results[i].crcstate,state_known_crc[known_id]);
                results[i].err++;
            }
            total_errors+=results[i].err;
        }
    }
    total_errors+=check_data_types();
    /* and report results */
    printstr("CoreMark Size    : ");
    printullong((ee_u32)results[0].size);
    printstr("\n");
    printstr("Total ticks      : ");
    printullong((ee_u32)total_time);
    printstr("\n");
#if HAS_FLOAT
    printstr("Total time (secs): ");
    printullong(time_in_secs(total_time));
    printstr("\n");
    if (time_in_secs(total_time) > 0)
        printstr("Iterations/Sec   : ");
    printint(default_num_contexts*results[0].iterations/time_in_secs(total_time));
    printstr("\n");
#else 
    printf("Total time (secs): %d\n",time_in_secs(total_time));
    if (time_in_secs(total_time) > 0)
        printf("Iterations/Sec   : %d\n",default_num_contexts*results[0].iterations/time_in_secs(total_time));
#endif
    if (time_in_secs(total_time) < 10) {
        printf("\nERROR! Must execute for at least 10 secs for a valid result!\n");
        total_errors++;
    }

    printstr("\nIterations       : ");
    printullong((ee_u32)default_num_contexts*results[0].iterations);
    printf("\nCompiler version : %s\n",COMPILER_VERSION);
    //printf("Compiler flags   : %s\n",COMPILER_FLAGS);
#if (MULTITHREAD>1)
    printf("Parallel %s : %d\n",PARALLEL_METHOD,default_num_contexts);
#endif
    printf("Memory location  : %s\n",MEM_LOCATION);
    /* output for verification */
    printf("seedcrc          : 0x%04x\n",seedcrc);
    if (results[0].execs & ID_LIST)
        for (i=0 ; i<default_num_contexts; i++)
            printf("[%d]crclist       : 0x%04x\n",i,results[i].crclist);
    if (results[0].execs & ID_MATRIX)
        for (i=0 ; i<default_num_contexts; i++)
            printf("[%d]crcmatrix     : 0x%04x\n",i,results[i].crcmatrix);
    if (results[0].execs & ID_STATE)
        for (i=0 ; i<default_num_contexts; i++)
            printf("[%d]crcstate      : 0x%04x\n",i,results[i].crcstate);
    for (i=0 ; i<default_num_contexts; i++)
        printf("[%d]crcfinal      : 0x%04x\n",i,results[i].crc);
    if (total_errors==0) {
        printf("\nCorrect operation validated. \nSee readme.txt for run and reporting rules.\n");
#if HAS_FLOAT
        if (known_id==3) {
//            printf("CoreMark 1.0 : %f / %s %s",default_num_contexts*results[0].iterations/time_in_secs(total_time),COMPILER_VERSION,COMPILER_FLAGS);
#if defined(MEM_LOCATION) && !defined(MEM_LOCATION_UNSPEC)
            printf(" / %s",MEM_LOCATION);
#else
            printf(" / %s",mem_name[MEM_METHOD]);
#endif

#if (MULTITHREAD>1)
            printf(" / %d:%s",default_num_contexts,PARALLEL_METHOD);
#endif
            printstr("\n");
        }
#endif
    }
    if (total_errors>0)
        printf("Errors detected\n");
    if (total_errors<0)
        printf("Cannot validate operation for these seed values, please compare with results on a known platform.\n");

#if (MEM_METHOD==MEM_MALLOC)
    for (i=0 ; i<MULTITHREAD; i++)
        portable_free(results[i].memblock[0]);
#endif
    /* And last call any target specific code for finalizing */
    portable_fini(&(results[0].port));

    return MAIN_RETURN_VAL;
}