| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifdef AUDIO_SCAN_DEBUG |
| 24 |
# define DEBUG_TRACE(...) PerlIO_printf(PerlIO_stderr(), __VA_ARGS__) |
| 25 |
#else |
| 26 |
# define DEBUG_TRACE(...) |
| 27 |
#endif |
| 28 |
|
| 29 |
|
| 30 |
#ifdef _MSC_VER |
| 31 |
#include "pinttypes.h" |
| 32 |
#else |
| 33 |
#include <inttypes.h> |
| 34 |
#endif |
| 35 |
|
| 36 |
#include "buffer.h" |
| 37 |
|
| 38 |
|
| 39 |
#define my_hv_store(a,b,c) hv_store(a,b,strlen(b),c,0) |
| 40 |
#define my_hv_store_ent(a,b,c) hv_store_ent(a,b,c,0) |
| 41 |
#define my_hv_fetch(a,b) hv_fetch(a,b,strlen(b),0) |
| 42 |
#define my_hv_exists(a,b) hv_exists(a,b,strlen(b)) |
| 43 |
#define my_hv_exists_ent(a,b) hv_exists_ent(a,b,0) |
| 44 |
#define my_hv_delete(a,b) hv_delete(a,b,strlen(b),0) |
| 45 |
|
| 46 |
#define GET_INT32BE(b) \ |
| 47 |
(i = (b[0] << 24) | (b[1] << 16) | b[2] << 8 | b[3], b += 4, i) |
| 48 |
|
| 49 |
int _check_buf(PerlIO *infile, Buffer *buf, int size, int min_size); |
| 50 |
off_t _file_size(PerlIO *infile); |
| 51 |
#ifdef AUDIO_SCAN_DEBUG |
| 52 |
void hexdump(unsigned char *data, uint32_t size); |
| 53 |
#endif |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
#ifdef CLOCK_CYCLE_TESTS |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
int64_t ReadTSC() { |
| 65 |
int res[2]; |
| 66 |
|
| 67 |
#if defined (_LP64) |
| 68 |
__asm__ __volatile__ ( |
| 69 |
"xorl %%eax,%%eax \n push %%rbx \n cpuid \n" |
| 70 |
::: "%rax", "%rcx", "%rdx"); |
| 71 |
__asm__ __volatile__ ( |
| 72 |
"rdtsc\n" |
| 73 |
: "=a" (res[0]), "=d" (res[1]) ); |
| 74 |
__asm__ __volatile__ ( |
| 75 |
"xorl %%eax,%%eax \n cpuid \n pop %%rbx \n" |
| 76 |
::: "%rax", "%rcx", "%rdx"); |
| 77 |
#else |
| 78 |
__asm__ __volatile__ ( |
| 79 |
"xorl %%eax,%%eax \n pushl %%ebx \n cpuid \n" |
| 80 |
::: "%eax", "%ecx", "%edx"); |
| 81 |
__asm__ __volatile__ ( |
| 82 |
"rdtsc\n" |
| 83 |
: "=a" (res[0]), "=d" (res[1]) ); |
| 84 |
__asm__ __volatile__ ( |
| 85 |
"xorl %%eax,%%eax \n cpuid \n popl %%ebx \n" |
| 86 |
::: "%eax", "%ecx", "%edx"); |
| 87 |
#endif |
| 88 |
|
| 89 |
return *(int64_t*)res; |
| 90 |
} |
| 91 |
|
| 92 |
#define CLOCK_START(count) { \ |
| 93 |
int ci; \ |
| 94 |
int64_t before, overhead; \ |
| 95 |
int64_t clocklist[count]; \ |
| 96 |
for (ci=0; ci < count; ci++) { \ |
| 97 |
before = ReadTSC(); \ |
| 98 |
clocklist[ci] = ReadTSC() - before; \ |
| 99 |
} \ |
| 100 |
overhead = clocklist[0]; \ |
| 101 |
for (ci=0; ci < count; ci++) { \ |
| 102 |
if (clocklist[ci] < overhead) overhead = clocklist[ci]; \ |
| 103 |
} \ |
| 104 |
for (ci=0; ci < count; ci++) { \ |
| 105 |
before = ReadTSC(); \ |
| 106 |
|
| 107 |
#define CLOCK_END(count) \ |
| 108 |
clocklist[ci] = ReadTSC() - before; \ |
| 109 |
} \ |
| 110 |
for (ci=0; ci < count; ci++) { \ |
| 111 |
clocklist[ci] -= overhead; \ |
| 112 |
} \ |
| 113 |
fprintf(stderr, "\n test clock cycles (overhead %lld)\n", overhead); \ |
| 114 |
for (ci = 0; ci < count; ci++) { \ |
| 115 |
fprintf(stderr, "%6i %14G\n", ci+1, (double)(clocklist[ci])); \ |
| 116 |
} \ |
| 117 |
} |
| 118 |
|
| 119 |
#else |
| 120 |
#define CLOCK_START(count) |
| 121 |
#define CLOCK_END(count) |
| 122 |
#endif |