X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Futil.h;h=cda59bfec453cf6c59461f2018b07e878b8b68f9;hb=81dffafe4b045c854d8a97f9c6c41877ee7669ca;hp=8eebd33195b02696b5842dbc17b9b4077df6e8d0;hpb=176092843ec9bc851c73c842facf92ad48ab03cb;p=retroray
diff --git a/src/util.h b/src/util.h
index 8eebd33..cda59bf 100644
--- a/src/util.h
+++ b/src/util.h
@@ -19,7 +19,7 @@ along with this program. If not, see .
#define UTIL_H_
#include
-#include "byteord.h" /* from imago, to sort out the sized int types mess */
+#include "sizeint.h"
#if defined(__WATCOMC__) || defined(_WIN32) || defined(__DJGPP__)
#include
@@ -27,6 +27,19 @@ along with this program. If not, see .
#include
#endif
+#ifdef __GNUC__
+#define PACKED __attribute__((packed))
+#else
+#define PACKED
+#endif
+
+unsigned int get_cs(void);
+#define get_cpl() ((int)(get_cs() & 3))
+
+void get_msr(uint32_t msr, uint32_t *low, uint32_t *high);
+void set_msr(uint32_t msr, uint32_t low, uint32_t high);
+
+
/* Non-failing versions of malloc/calloc/realloc. They never return 0, they call
* demo_abort on failure. Use the macros, don't call the *_impl functions.
*/
@@ -44,4 +57,28 @@ int match_prefix(const char *str, const char *prefix);
void enable_fpexcept(void);
void disable_fpexcept(void);
+#ifndef INLINE
+#if (__STDC_VERSION__ >= 199901) || defined(__GNUC__)
+#define INLINE inline
+#else
+#define INLINE __inline
+#endif
+#endif
+
+#if defined(__i386__) || defined(__386__) || defined(MSDOS)
+
+/* fast conversion of double -> 32bit int
+ * for details see:
+ * - http://chrishecker.com/images/f/fb/Gdmfp.pdf
+ * - http://stereopsis.com/FPU.html#convert
+ */
+static INLINE int32_t cround64(double val)
+{
+ val += 6755399441055744.0;
+ return *(int32_t*)&val;
+}
+#else
+#define cround64(x) ((int32_t)(x))
+#endif
+
#endif /* UTIL_H_ */