Debian Codegraph @

include/common.h

raw symbols SCIP
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 */
16
17 // Enable for debug output
18 //#define AUDIO_SCAN_DEBUG
19
20 // Enable to support clock cycle test counts (x86 only)
21 //#define CLOCK_CYCLE_TESTS
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 /* for PRIu64 */
30 #ifdef _MSC_VER
31 #include "pinttypes.h"
32 #else
33 #include <inttypes.h>
34 #endif
35
36 #include "buffer.h"
37
38 /* strlen the length automatically */
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 // Based on code from http://www.agner.org/optimize/
56 // Test code to count clock cycles of some portion of the code
57 // Wrap code to be tested with CLOCK_START(n) ... CLOCK_END(n)
58 // where n is a count of iterations to run. Code must support
59 // being run more than once.
60 #ifdef CLOCK_CYCLE_TESTS
61
62 // Read time stamp counter
63 // The return value is the internal clock count
64 int64_t ReadTSC() {
65 int res[2]; // store 64 bit result here
66
67 #if defined (_LP64) // 64 bit mode
68 __asm__ __volatile__ ( // serialize (save rbx)
69 "xorl %%eax,%%eax \n push %%rbx \n cpuid \n"
70 ::: "%rax", "%rcx", "%rdx");
71 __asm__ __volatile__ ( // read TSC, store edx:eax in res
72 "rdtsc\n"
73 : "=a" (res[0]), "=d" (res[1]) );
74 __asm__ __volatile__ ( // serialize again
75 "xorl %%eax,%%eax \n cpuid \n pop %%rbx \n"
76 ::: "%rax", "%rcx", "%rdx");
77 #else // 32 bit mode
78 __asm__ __volatile__ ( // serialize (save ebx)
79 "xorl %%eax,%%eax \n pushl %%ebx \n cpuid \n"
80 ::: "%eax", "%ecx", "%edx");
81 __asm__ __volatile__ ( // read TSC, store edx:eax in res
82 "rdtsc\n"
83 : "=a" (res[0]), "=d" (res[1]) );
84 __asm__ __volatile__ ( // serialize again
85 "xorl %%eax,%%eax \n cpuid \n popl %%ebx \n"
86 ::: "%eax", "%ecx", "%edx");
87 #endif
88
89 return *(int64_t*)res; // return result
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