7 /* fast conversion of double -> 32bit int
9 * - http://chrishecker.com/images/f/fb/Gdmfp.pdf
10 * - http://stereopsis.com/FPU.html#convert
12 static inline int32_t cround64(double val)
14 val += 6755399441055744.0;
15 return *(int32_t*)&val;
18 static inline float rsqrt(float x)
20 float xhalf = x * 0.5f;
21 int32_t i = *(int32_t*)&x;
22 i = 0x5f3759df - (i >> 1);
24 x = x * (1.5f - xhalf * x * x);
28 extern uint32_t perf_start_count, perf_interval_count;
30 #define memset16(dest, val, count) \
32 uint32_t dummy1, dummy2; \
35 "test $1, %%ecx\n\t" \
42 "shl $16, %%eax\n\t" \
46 : "=D"(dummy1), "=c"(dummy2) \
47 : "0"(dest), "a"((uint16_t)(val)), "1"(count) \
48 : "flags", "memory"); \
52 #define memcpy64(dest, src, count) asm volatile ( \
54 "movq (%1), %%mm0\n\t" \
55 "movq %%mm0, (%0)\n\t" \
61 :: "r"(dest), "r"(src), "r"(count) \
64 #define memcpy64(dest, src, count) memcpy(dest, src, (count) << 3)
68 #define perf_start() asm volatile ( \
69 "xor %%eax, %%eax\n" \
73 : "=m"(perf_start_count) \
74 :: "%eax", "%ebx", "%ecx", "%edx")
76 #define perf_end() asm volatile ( \
77 "xor %%eax, %%eax\n" \
82 : "=m"(perf_interval_count) \
83 : "m"(perf_start_count) \
84 : "%eax", "%ebx", "%ecx", "%edx")
85 #endif /* !def NO_PENTIUM */
87 #define debug_break() \
88 asm volatile("int $3")
93 unsigned int get_cs(void);
94 #define get_cpl() ((int)(get_cs() & 3))
96 void get_msr(uint32_t msr, uint32_t *low, uint32_t *high);
97 void set_msr(uint32_t msr, uint32_t low, uint32_t high);
100 /* Non-failing versions of malloc/calloc/realloc. They never return 0, they call
101 * demo_abort on failure. Use the macros, don't call the *_impl functions.
103 #define malloc_nf(sz) malloc_nf_impl(sz, __FILE__, __LINE__)
104 void *malloc_nf_impl(size_t sz, const char *file, int line);
105 #define calloc_nf(n, sz) calloc_nf_impl(n, sz, __FILE__, __LINE__)
106 void *calloc_nf_impl(size_t num, size_t sz, const char *file, int line);
107 #define realloc_nf(p, sz) realloc_nf_impl(p, sz, __FILE__, __LINE__)
108 void *realloc_nf_impl(void *p, size_t sz, const char *file, int line);
109 #define strdup_nf(s) strdup_nf_impl(s, __FILE__, __LINE__)
110 char *strdup_nf_impl(const char *s, const char *file, int line);