2 RetroRay - integrated standalone vintage modeller/renderer
3 Copyright (C) 2023 John Tsiombikas <nuclear@mutantstargoat.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
24 #if defined(__WATCOMC__) || defined(_WIN32) || defined(__DJGPP__)
31 #define PACKED __attribute__((packed))
36 unsigned int get_cs(void);
37 #define get_cpl() ((int)(get_cs() & 3))
39 void get_msr(uint32_t msr, uint32_t *low, uint32_t *high);
40 void set_msr(uint32_t msr, uint32_t low, uint32_t high);
43 /* Non-failing versions of malloc/calloc/realloc. They never return 0, they call
44 * demo_abort on failure. Use the macros, don't call the *_impl functions.
46 #define malloc_nf(sz) malloc_nf_impl(sz, __FILE__, __LINE__)
47 void *malloc_nf_impl(size_t sz, const char *file, int line);
48 #define calloc_nf(n, sz) calloc_nf_impl(n, sz, __FILE__, __LINE__)
49 void *calloc_nf_impl(size_t num, size_t sz, const char *file, int line);
50 #define realloc_nf(p, sz) realloc_nf_impl(p, sz, __FILE__, __LINE__)
51 void *realloc_nf_impl(void *p, size_t sz, const char *file, int line);
52 #define strdup_nf(s) strdup_nf_impl(s, __FILE__, __LINE__)
53 char *strdup_nf_impl(const char *s, const char *file, int line);
55 int match_prefix(const char *str, const char *prefix);
57 void enable_fpexcept(void);
58 void disable_fpexcept(void);
61 #if (__STDC_VERSION__ >= 199901) || defined(__GNUC__)
64 #define INLINE __inline
68 #if defined(__i386__) || defined(__386__) || defined(MSDOS)
70 /* fast conversion of double -> 32bit int
72 * - http://chrishecker.com/images/f/fb/Gdmfp.pdf
73 * - http://stereopsis.com/FPU.html#convert
75 static INLINE int32_t cround64(double val)
77 val += 6755399441055744.0;
78 return *(int32_t*)&val;
81 #define cround64(x) ((int32_t)(x))