From 320e70d8c4ef4650aa8c3c18ab24faa799b45472 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 5 Sep 2011 17:18:06 +0000 Subject: [PATCH] core: a few compilation fixes for non-GCC compilers. --- src/core.h | 13 +++++++++++-- src/debug/quad.cpp | 8 +++++++- src/log.h | 12 +++++++----- src/trig.cpp | 46 ++++++++++++++++++++++++++++++++-------------- 4 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/core.h b/src/core.h index fae13005..cc4bd49e 100644 --- a/src/core.h +++ b/src/core.h @@ -25,8 +25,17 @@ #endif // Optimisation helpers -#define __likely(x) __builtin_expect(!!(x), 1) -#define __unlikely(x) __builtin_expect(!!(x), 0) +#if defined __GNUC__ +# define __likely(x) __builtin_expect(!!(x), 1) +# define __unlikely(x) __builtin_expect(!!(x), 0) +# define INLINEATTR __attribute__((always_inline)) +# define FP_USE(x) __asm__("" : "+m" (x)) +#else +# define __likely(x) x +# define __unlikely(x) x +# define INLINEATTR +# define FP_USE(x) (void)(x) +#endif // Base types #include "trig.h" diff --git a/src/debug/quad.cpp b/src/debug/quad.cpp index 91484b39..91fc8e18 100644 --- a/src/debug/quad.cpp +++ b/src/debug/quad.cpp @@ -12,6 +12,12 @@ # include "config.h" #endif +#ifdef WIN32 +# define _USE_MATH_DEFINES /* for M_PI */ +# define WIN32_LEAN_AND_MEAN +# include +#endif + #include #include #include @@ -82,9 +88,9 @@ private: /* Cache a list of points for a sine wave, ensuring constant spacing * between consecutive points. */ static int const SINE_SIZE = 256; - static float const SINE_SPACE = 0.01f; GLfloat const *GetSineArray() { + static float const SINE_SPACE = 0.01f; float x = 0.0f; for (npoints = 0; npoints < SINE_SIZE && x <= 1.0f; npoints++) { diff --git a/src/log.h b/src/log.h index 5d528529..067a2e1f 100644 --- a/src/log.h +++ b/src/log.h @@ -26,12 +26,14 @@ class Log { public: #ifdef __GNUC__ -# define LOL_FMT_ATTR __attribute__((format(printf, 1, 2))) +# define LOL_FMT_ATTR(n, p) __attribute__((format(printf, n, p))) +#else +# define LOL_FMT_ATTR(n, p) #endif - static void Debug(char const *format, ...) LOL_FMT_ATTR; - static void Info(char const *format, ...) LOL_FMT_ATTR; - static void Warn(char const *format, ...) LOL_FMT_ATTR; - static void Error(char const *format, ...) LOL_FMT_ATTR; + static void Debug(char const *format, ...) LOL_FMT_ATTR(1, 2); + static void Info(char const *format, ...) LOL_FMT_ATTR(1, 2); + static void Warn(char const *format, ...) LOL_FMT_ATTR(1, 2); + static void Error(char const *format, ...) LOL_FMT_ATTR(1, 2); #undef LOL_FMT_ATTR }; diff --git a/src/trig.cpp b/src/trig.cpp index a2b7d958..a6b90cf4 100644 --- a/src/trig.cpp +++ b/src/trig.cpp @@ -16,6 +16,8 @@ # include #endif +#include + #include "core.h" using namespace std; @@ -36,7 +38,11 @@ static const double NEG_ONE = -1.0; static const double HALF = 0.5; static const double QUARTER = 0.25; static const double TWO = 2.0; +#if defined __GNUC__ static const double VERY_SMALL_NUMBER = 0x1.0p-128; +#else +static const double VERY_SMALL_NUMBER = 3e-39; +#endif static const double TWO_EXP_52 = 4503599627370496.0; static const double TWO_EXP_54 = 18014398509481984.0; @@ -88,7 +94,13 @@ static const double TC[] = }; /* Custom intrinsics */ -#define INLINEATTR __attribute__((always_inline)) +#if defined __GNUC__ +# define INLINEATTR __attribute__((always_inline)) +# define FP_USE(x) __asm__("" : "+m" (x)) +#else +# define INLINEATTR +# define FP_USE(x) (void)(x) +#endif #if defined __CELLOS_LV2__ static inline double lol_fctid(double x) INLINEATTR; @@ -100,8 +112,10 @@ static inline double lol_fres(double x) INLINEATTR; static inline double lol_fdiv(double a, double b) INLINEATTR; #endif static inline double lol_fabs(double x) INLINEATTR; +#if defined __GNUC__ static inline double lol_round(double x) INLINEATTR; static inline double lol_trunc(double x) INLINEATTR; +#endif #if defined __CELLOS_LV2__ static inline double lol_fctid(double x) @@ -200,11 +214,14 @@ static inline double lol_fabs(double x) __asm__ ("fabs %0, %1" : "=f" (r) : "f" (x)); return r; -#else +#elif defined __GNUC__ return __builtin_fabs(x); +#else + return fabs(x); #endif } +#if defined __GNUC__ static inline double lol_round(double x) { #if defined __CELLOS_LV2__ @@ -222,6 +239,7 @@ static inline double lol_trunc(double x) return __builtin_trunc(x); #endif } +#endif double lol_sin(double x) { @@ -253,12 +271,12 @@ double lol_sin(double x) sign = lol_fsel(is_even, sign, -sign); #else double num_cycles = absx + TWO_EXP_52; - __asm__("" : "+m" (num_cycles)); num_cycles -= TWO_EXP_52; + FP_USE(num_cycles); num_cycles -= TWO_EXP_52; double is_even = TWO * num_cycles - ONE; - __asm__("" : "+m" (is_even)); is_even += TWO_EXP_54; - __asm__("" : "+m" (is_even)); is_even -= TWO_EXP_54; - __asm__("" : "+m" (is_even)); + FP_USE(is_even); is_even += TWO_EXP_54; + FP_USE(is_even); is_even -= TWO_EXP_54; + FP_USE(is_even); is_even -= TWO * num_cycles - ONE; double sign = is_even; #endif @@ -321,12 +339,12 @@ double lol_cos(double x) double sign = lol_fsel(is_even, ONE, NEG_ONE); #else double num_cycles = absx + TWO_EXP_52; - __asm__("" : "+m" (num_cycles)); num_cycles -= TWO_EXP_52; + FP_USE(num_cycles); num_cycles -= TWO_EXP_52; double is_even = TWO * num_cycles - ONE; - __asm__("" : "+m" (is_even)); is_even += TWO_EXP_54; - __asm__("" : "+m" (is_even)); is_even -= TWO_EXP_54; - __asm__("" : "+m" (is_even)); + FP_USE(is_even); is_even += TWO_EXP_54; + FP_USE(is_even); is_even -= TWO_EXP_54; + FP_USE(is_even); is_even -= TWO * num_cycles - ONE; double sign = is_even; #endif @@ -396,12 +414,12 @@ void lol_sincos(double x, double *sinx, double *cosx) double cos_sign = lol_fsel(is_even, ONE, NEG_ONE); #else double num_cycles = absx + TWO_EXP_52; - __asm__("" : "+m" (num_cycles)); num_cycles -= TWO_EXP_52; + FP_USE(num_cycles); num_cycles -= TWO_EXP_52; double is_even = TWO * num_cycles - ONE; - __asm__("" : "+m" (is_even)); is_even += TWO_EXP_54; - __asm__("" : "+m" (is_even)); is_even -= TWO_EXP_54; - __asm__("" : "+m" (is_even)); + FP_USE(is_even); is_even += TWO_EXP_54; + FP_USE(is_even); is_even -= TWO_EXP_54; + FP_USE(is_even); is_even -= TWO * num_cycles - ONE; double sin_sign = is_even; double cos_sign = is_even;