7 typedef unsigned char uint8_t;
9 typedef unsigned short uint16_t;
11 typedef unsigned int uint32_t;
12 typedef unsigned long intptr_t;
18 #define INLINE __inline
19 #define PACKED __attribute__((packed))
21 #elif defined(__WATCOMC__)
22 #define INLINE __inline
30 #define BSWAP16(x) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
32 ((((x) >> 24) & 0xff) | \
33 (((x) >> 8) & 0xff00) | \
34 (((x) << 8) & 0xff0000) | \
38 extern short sinlut[];
40 #define SIN(x) (int)sinlut[(x) & 0x7ff]
41 #define COS(x) (int)sinlut[((x) + 512) & 0x7ff]
43 int mask_to_shift(unsigned int mask);
45 #if defined(__i386__) || defined(__x86_64__) || defined(__386__) || defined(MSDOS)
46 /* fast conversion of double -> 32bit int
48 * - http://chrishecker.com/images/f/fb/Gdmfp.pdf
49 * - http://stereopsis.com/FPU.html#convert
51 static INLINE int32_t cround64(double val)
53 val += 6755399441055744.0;
54 return *(int32_t*)&val;
57 #define cround64(x) ((int32_t)(x))
60 static INLINE float rsqrt(float x)
62 float xhalf = x * 0.5f;
63 int32_t i = *(int32_t*)&x;
64 i = 0x5f3759df - (i >> 1);
66 x = x * (1.5f - xhalf * x * x);
70 extern uint32_t perf_start_count, perf_interval_count;
73 void memset16(void *dest, uint16_t val, int count);
74 #pragma aux memset16 = \
77 "jz memset16_dwords" \
90 void memcpy64(void *dest, void *src, int count);
91 #pragma aux memcpy64 = \
100 parm[ebx][edx][ecx] \
103 #define memcpy64(dest, src, count) memcpy(dest, src, (count) << 3)
106 void perf_start(void);
107 #pragma aux perf_start = \
111 "mov [perf_start_count], eax" \
112 modify[eax ebx ecx edx];
115 #pragma aux perf_end = \
119 "sub eax, [perf_start_count]" \
120 "mov [perf_interval_count], eax" \
121 modify [eax ebx ecx edx];
123 void debug_break(void);
124 #pragma aux debug_break = "int 3";
128 #if defined(__i386__) || defined(__x86_64__)
129 #define memset16(dest, val, count) asm volatile ( \
138 "shl $16, %%eax\n\t" \
142 :: "D"(dest), "a"((uint16_t)(val)), "c"(count) \
145 static void INLINE memset16(void *dest, uint16_t val, int count)
147 uint16_t *ptr = dest;
148 while(count--) *ptr++ = val;
153 #define memcpy64(dest, src, count) asm volatile ( \
155 "movq (%1), %%mm0\n\t" \
156 "movq %%mm0, (%0)\n\t" \
162 :: "r"(dest), "r"(src), "r"(count) \
165 #define memcpy64(dest, src, count) memcpy(dest, src, (count) << 3)
168 #define perf_start() asm volatile ( \
169 "xor %%eax, %%eax\n" \
173 : "=m"(perf_start_count) \
174 :: "%eax", "%ebx", "%ecx", "%edx")
176 #define perf_end() asm volatile ( \
177 "xor %%eax, %%eax\n" \
182 : "=m"(perf_interval_count) \
183 : "m"(perf_start_count) \
184 : "%eax", "%ebx", "%ecx", "%edx")
186 #define debug_break() \
187 asm volatile ("int $3")
191 void __inline memset16(void *dest, uint16_t val, int count)
212 #define perf_start() \
218 mov [perf_start_count], eax \
228 sub eax, [perf_start_count] \
229 mov [perf_interval_count], eax \
233 #define debug_break() \