int main(int argc, char **argv) { int t1, t2, t3, t4; double r = 0.0; t1 = ReadTSC(); r += testfunc(); t2 = ReadTSC(); r += testfunc(); t3 = ReadTSC(); r += testfunc(); t4 = ReadTSC(); printf ("Times: %i, %i, %i: result %f\n", t2-t1, t3-t2, t4-t3, r); t1 = ReadTSC(); r += testfunc2(); t2 = ReadTSC(); r += testfunc2(); t3 = ReadTSC(); r += testfunc2(); t4 = ReadTSC(); printf ("Times: %i, %i, %i: result %f\n", t2-t1, t3-t2, t4-t3, r); getchar(); return 0; }
static ssize_t audio_write (struct file *file, const char *buf, size_t count, loff_t *offset) { struct audio_state *state = &audio_state; // ssize_t result = 0; int head; unsigned int start; unsigned int stop; if (offset != &file->f_pos) return -ESPIPE; if (count != (1152 * 4)) { /* unexpected count... throw away the data. */ printk ("Audio: unexpected count %d\n", count); return count; } while (frames_free (state) == 0) /* no space available... */ { if (file->f_flags & O_NONBLOCK) return -EAGAIN; // printk ("Audio: sleeping...\n"); if (wait_event_interruptible (state->wq, frames_free (state) > 0)) return -ERESTARTSYS; } head = state->frame_head; // printk ("head,tail,free = %2d,%2d,%2d\n", head, state->frame_tail, frames_free (state)); start = ReadTSC(); if (copy_from_user (&state->frame[head], buf, count)) return -EFAULT; stop = ReadTSC(); // printk ("%d uSec\n", (stop - start) / ReadTSCMHz()); if (++head >= AUDIO_FRAMES) head = 0; state->frame_head = head; return count; }
CText::CText() { m_pbBuffer = NULL; m_pIndex = NULL; m_dwBufferSize = 0; m_dwIndexCount = 0; m_dwMaxIndexCount = 80000; m_dwKey = ReadTSC(); m_hHeap = GetProcessHeap(); }
ULONGLONG CPUclock::ClockRatePerfCt(unsigned long lnSamplePeriod) { LARGE_INTEGER PerfCt, OldPerfCt, PerfFreq; ULARGE_INTEGER Cycle, OldCycle, ClockHz; QueryPerformanceFrequency(&PerfFreq); QueryPerformanceCounter(&OldPerfCt); ReadTSC(&OldCycle.u.LowPart, &OldCycle.u.HighPart); Sleep(lnSamplePeriod); QueryPerformanceCounter(&PerfCt); ReadTSC(&Cycle.u.LowPart, &Cycle.u.HighPart); ClockHz.QuadPart = (ULONGLONG)(Cycle.QuadPart - OldCycle.QuadPart); ClockHz.QuadPart = (ULONGLONG)(ClockHz.QuadPart * PerfFreq.QuadPart) / (PerfCt.QuadPart - OldPerfCt.QuadPart); return ClockHz.QuadPart; }
static ssize_t audio_write (struct file *file, const char *buf, size_t count, loff_t *offset) { unsigned int start; unsigned int stop; int tail, ret = count; int required = count; unsigned long flags; if (audio_state.sample_size == 8) required <<= 1; if (audio_state.channels == 1) required <<= 1; /* No seeking allowed on this device */ if (offset != &file->f_pos) return -ESPIPE; DBG(3, "%s: count = %d, sample_size = %d, channels = %d, " "required = %d\n", __FUNCTION__, count, audio_state.sample_size, audio_state.channels, required); DBG(3, "%s: INT status = %s\n", __FUNCTION__, (ATU_Registers->ETU_int_status & ETU_INT_WR_CH1L_HALF) ? "Pending" : "Idle"); down(&audio_state.sem); if (0) { /* Special case, madplay using internal SRAM */ audio_state.use_sram = 1; if (count > 16384) panic("Madplay's buffer too big\n"); } else { audio_state.use_sram = 0; } while (frames_free() < required) { /* no space available... */ if (file->f_flags & O_NONBLOCK) { ret = -EAGAIN; goto wdone; } DBG (3, "Audio: sleeping...\n"); if (wait_event_interruptible (audio_state.wq, frames_free() >= required)) { ret = -ERESTARTSYS; goto wdone; } } DBG (3, "head = %d, tail = %d, free = %d\n", audio_state.head, audio_state.tail, frames_free()); tail = audio_state.tail; start = ReadTSC(); if (audio_state.channels != 2 || audio_state.sample_size != 16) { if (translate_from_user(buf, count)) { ret = -EFAULT; goto wdone; } } else { if (copy_userbuf(buf, count)) { ret = -EFAULT; goto wdone; } } stop = ReadTSC(); DBG (3, "%d uSec\n", (stop - start) / ReadTSCMHz()); local_irq_save(flags); if (audio_state.first_write) { if (frames_used() >= (AUDIO_FRAMES * 3) / 4) { ATU_Registers->ETU_int_set |= ETU_INT_WR_CH1L_EMPTY; audio_state.first_write = 0; } } else { ATU_Registers->ETU_int_set |= ETU_INT_WR_CH1L_EMPTY; } local_irq_restore(flags); wdone: up(&audio_state.sem); return ret; }
int main () { // test InstructionSet() printf("\nInstructionSet = %i", InstructionSet()); // test cpuid_abcd int abcd[4]; char s[16]; cpuid_abcd(abcd, 0); *(int*)(s+0) = abcd[1]; // ebx *(int*)(s+4) = abcd[3]; // edx *(int*)(s+8) = abcd[2]; // ecx s[12] = 0; // terminate string printf("\nVendor string = %s", s); // test ProcessorName() printf("\nProcessorName = %s", ProcessorName()); // test CpuType int vendor, family, model; CpuType(&vendor, &family, &model); printf("\nCpuType: vendor %i, family 0x%X, model 0x%X", vendor, family, model); // test DataCacheSize printf("\nData cache size: L1 %ikb, L2 %ikb, L3 %ikb", (int)DataCacheSize(1)/1024, (int)DataCacheSize(2)/1024, (int)DataCacheSize(3)/1024); // test ReadTSC() ReadTSC(); int tsc = (int)ReadTSC(); tsc = (int)ReadTSC() - tsc; printf("\nReadTSC takes %i clocks\n\n", tsc); // test Round(); double d; for (d = -1; d <= 1; d += 0.5) { printf("Round %f = %i = %i\n", d, Round(d), Round(float(d))); } // Test memory and string functions int i, n; const int strsize = 256; char string1[strsize], string2[strsize]; const char * teststring = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 @`'{}[]()<>"; // Initialize strings A_memset(string1, 0, strsize); A_memset(string2, 0, strsize); // Test A_strcpy, A_strcat, A_strlen A_strcpy(string1, teststring); n = strsize/(int)A_strlen(teststring); for (i = 0; i < n-1; i++) { A_strcat(string1, teststring); } if (A_strlen(string1) != n * A_strlen(teststring)) Failure("A_strcpy, A_strcat, A_strlen"); // Test A_stricmp A_memcpy(string2, string1, strsize); string2[4] ^= 0x20; string1[30] ^= 0x20; // Change case if (A_stricmp(string1, string2) != 0) Failure("A_stricmp"); string2[8] += 2; // Make strings different if (A_stricmp(string1, string2) >= 0) Failure("A_stricmp"); string2[7] -= 2; // Make strings different if (A_stricmp(string1, string2) <= 0) Failure("A_stricmp"); // test A_strtolower and A_strtoupper A_strcpy(string1, teststring); A_strcpy(string2, teststring); A_strtolower(string1); A_strtoupper(string2); printf("\nstring converted to lower and upper case:\n%s\n%s\n%s", teststring, string1, string2); // test strspn and strcspn int n1, n2; const int nset = 4; const char * tset[] = {"abc", "", "01234567890123456789", "abcdefghijklmnopqrstuvwxyz"}; for (i = 0; i < nset; i++) { n1 = A_strspn(teststring, tset[i]); n2 = strspn(teststring, tset[i]); if (n1 != n2) Failure("A_strspn"); n1 = A_strcspn(teststring, tset[i]); n2 = strcspn(teststring, tset[i]); if (n1 != n2) Failure("A_strcspn"); } // Test A_memmove with overlapping source and destination A_memcpy(string2, string1, strsize); A_memcpy(string1+5, string1+12, 12); memcpy (string2+5, string2+12, 12); if (A_stricmp(string1, string2) != 0) Failure("memcpy"); A_memcpy(string1+5, string1+12, 130); memcpy (string2+5, string2+12, 130); if (A_stricmp(string1, string2) != 0) Failure("memcpy"); A_memmove(string1+5, string1+2, 12); memmove (string2+5, string2+2, 12); if (A_stricmp(string1, string2) != 0) Failure("A_memmove"); A_memmove(string1+3, string1+8, 12); memmove (string2+3, string2+8, 12); if (A_stricmp(string1, string2) != 0) Failure("A_memmove"); A_memmove(string1+41, string1+30, 100); memmove (string2+41, string2+30, 100); if (A_stricmp(string1, string2) != 0) Failure("A_memmove"); A_memmove(string1+32, string1+48, 177); memmove (string2+32, string2+48, 177); if (A_stricmp(string1, string2) != 0) Failure("A_memmove"); printf("\n\nTests passed OK\n"); return 0; }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { MSG msg; BOOL done = FALSE; ::hInst = hInst; if (!CreateGLWindow()) return 0; ShowWindow(hWnd, SW_SHOW); ReSizeGLScene(WIDTH, HEIGHT); glewInit(); /************* GL things ***************/ if (!InitGL()) { MessageBox(0, "Fail to init GL", "ERROR", MB_OK); return FALSE; } /************* Game things ***************/ InitClasses(); LARGE_INTEGER _FREQ; QueryPerformanceFrequency(&_FREQ); tickFreq = (double)_FREQ.QuadPart; MersenneRandomInit((int)ReadTSC()); // load textures s_Texture->LoadAllTextures(); //************* Game preinit ***************/ s_World->LoadWorld(); m_Player->eyepos = float3(20, 20, 80); m_Player->theta = PI/2; m_Player->phi = PI/4; //************* Event loop ***************/ ShowCursor(false); while (!done) { if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) done = TRUE; else { TranslateMessage(&msg); DispatchMessage(&msg); } } else { if (active && !DrawGLScene()) { done = TRUE; } else { SwapBuffers(hDC); } } } ShowCursor(true); DeInitClasses(); wglMakeCurrent(0, 0); wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); DestroyWindow(hWnd); UnregisterClass("OpenGL", hInst); KillFont(); return 0; }
int test_scan645() { int i, j, k; int lenb = 72025; // 612311; long c1, c2; uint8_t *tmp = (uint8_t*)calloc(1, lenb); FILE *filp = fopen("/home/greg/t509/u610-equa/mjpeg800x448-8.dat", "rb"); fread(tmp, 1, lenb, filp); fclose(filp); // j = k = 0; c1 = ReadTSC(); for(i = 0 ; i < lenb ; i++) { if (tmp[i] == 0xFF) { j++; if (tmp[i+1] == 0x00) { k++; } } } c2 = ReadTSC(); printf("%d FF (%d FF00) in file for %ld\n", j, k, (c2 - c1)); // i = j = k = 0; uint8_t *ptr = tmp + 220, *lim = tmp + lenb; c1 = ReadTSC(); while(ptr < lim) { if (*ptr == 0xFF) { j++; if (ptr[1] == 0x00) { k++; } } ptr++; } c2 = ReadTSC(); printf("%d FF (%d FF00) in file for %ld : %02X%02X\n", j, k, (c2 - c1), tmp[lenb-2], tmp[lenb-1]); // scan test int res[20] = {0}; c1 = ReadTSC(); uint8_t *ret = scan645(tmp, lenb, res); c2 = ReadTSC(); printf("Scan : %ld in %.1f Kµ (%.3f) KHz | %d | %d | %d | %d / %d |\n", ret, 0.001*(c2 - c1), 1.5e6 / (c2 - c1), res[0], res[1], res[2], res[3], 72027); // uint8_t *l = (uint8_t*) tmp; // for(i = 0 ; i < 16 ; i++) l[i] = i; // l[2] = 0xFF; // l[3] = 0x00; // uint8_t *la = (uint8_t*) res; memset(res, 0, 16); c1 = ReadTSC(); ret = scan645o(tmp + 220, lenb - 220, res); c2 = ReadTSC(); char *dump(uint8_t *p) {static char c[89];int i;for(i=0;i<16;i++) snprintf(c+3*i,10,"%02X ",p[i]);return c;} printf("Ai : %s\n", dump(la)); printf("Bi : %s\n", dump(la+16)); printf("Ci : %s\n", dump(la+32)); printf("%016lX : %016lX - %016lX\n", ret); printf("Scan-o : %ld in %.1f Kµ (%.3f) KHz | %d | %d | %d | %d - %d |\n", ret, 0.001*(c2 - c1), 1.5e6 / (c2 - c1), res[0], res[1], res[2], res[3], 72025); return 0; }
int main() { int i, j; long c1, c2; //return testacl2(); //return ffm_test1(); //return enc_ffm_test(); //if (enc_ffm_test() < 0) return 0; enc_ffm_test(); // ffm_test2(); return 0; // //FILE *filp = fopen("/home/greg/t509/u610-equa/mjpeg800x448-8.dat", "rb"); FILE *filp = fopen("mjpeg_encode.out", "rb"); fseek(filp, 0, SEEK_END); fpos_t p; fgetpos(filp, &p); int lenb = p.__pos; // 612311; uint8_t *tmp = (uint8_t*)calloc(1, lenb); fseek(filp, 0, SEEK_SET); fread(tmp, 1, lenb, filp); fclose(filp); printf("Load %d bytes\n", lenb); // mjpeg645_img *mjpeg = alloc_mjpeg645_image(tmp, lenb); mjpeg->pixels = NULL; // uint8_t *log = mjpeg->ext1 = calloc(1024, 1024); // Scan // while(1) { mjpeg->ext1 = log; c1 = ReadTSC(); long r = mjpeg_decode645(mjpeg, NULL, lenb, NULL); c2 = ReadTSC(); LOG("Decode: return %ld (%ld) for %ld µ", r , r - (long)mjpeg->data, c2 - c1); int *part = (int*)log; float *fart = (float*)log; for(i = 0 ; i < 100000 ; i++) { if (part[i] == -9999) { printf("X\n"); } else if (part[i] == -9998) { printf("| "); } else if (part[i] == -10000) { break; } else if (*((long*)(log + 4*i)) == 0) { if (*((long*)(log + 4*i + 8)) == 0) if (*((long*)(log + 4*i + 16)) == 0) if (*((long*)(log + 4*i + 24)) == 0) if (*((long*)(log + 4*i + 32)) == 0) if (*((long*)(log + 4*i + 40)) == 0) if (*((long*)(log + 4*i + 48)) == 0) if (*((long*)(log + 4*i + 56)) == 0) break; } else { //printf("%d ", part[i]); printf("%.2f ", fart[i]); //printf("%08X ", part[i]); } } printf("\n"); // if (mjpeg->size > 10000) { // continue; // } break; // printf("Decode sequence:\n"); // int w = 35; // for(j = 0 ; j < 24 ; j++) { // for(i = 0 ; i < w ; i++) { // printf("%u ", hres[i + w * j]); // } // printf("\n"); // } // printf("Done\n"); int stats[64] = {0}; int min = 0; int max = 0; printf("Decode sequence:\n|"); for(i = 0 ; i < 70024 ; i++) { if (log[i] != 0xFF) { printf("%3u|", log[i]); } else { printf(" - |\n|", log[i]); if (*((long*)(log + i + 1)) == 0) break; } if (log[i] == 255 && log[i-2] == 0) { min++; if (log[i-1] > max) max = log[i-1]; stats[log[i-1]]++; } } printf("\n"); printf("Done\n"); printf("Stats for %d blocks, max = %d\n", min, max); max = 0; for(i = 0 ; i < 64 ; i++) { max += stats[i]; } min = 0; for(i = 0 ; i < 64 ; i++) { min += stats[i]; printf("NB[%d] = %d ( %.2f - %.2f )\n", i, stats[i], 100. * stats[i] / max, 100.*min/max); } } // -------------------------------------------------------------------------------- // // ### // long l1, l2; // // // uint8_t *tres = calloc(1024, 1024); // filp = fopen("hdc.out", "rb"); // fread(tres, 1, 1024*1024, filp); // fclose(filp); // printf("Results:\n"); // for(i = 0 ; i < 32 ; i++) printf("%u ", tres[i]); // printf("\n"); // // // // // printf("Starting asm tests\n"); // long symb = 0; // uint8_t *add; // int cofs = 500000; // uint16_t cod = 55807; // l1 = ReadTSC(); // for(i = cofs/50000 ; i >= 0 ; i--) { // 10 * 50000 // //add = (uint8_t*)hu2fman645(mjpeg->data, 50000, hres); // //add = (uint8_t*)hu2fman645(&cod, 1, hres); // add = (uint8_t*)huf4man645(&cod, hres); // } // l2 = ReadTSC(); // printf("End of asm tests\n"); // LOG("Huffman: stop at %ld for %ld = %ld (%ld M - %.1f ms)", add - mjpeg->data, l2 - l1, (l2 - l1) / ((cofs/50000)*50000), 1.*(l2 - l1) / 1.5e6, (l2 - l1) / 1000000); // // // printf("Asm: %ld\n", add); // for(i = 0 ; i < 32 ; i++) printf("%u ", hres[i]); // printf("\n"); // // // i = 0; // while(i < 1024*1024 && (hres[i] == tres[i])) i++; // printf("Equals n'til %d\n", i); return 0; err: free_mjpeg645_image(&mjpeg); return -1; }