Browse Source

core: a few compilation fixes for non-GCC compilers.

legacy
Sam Hocevar sam 13 years ago
parent
commit
320e70d8c4
4 changed files with 57 additions and 22 deletions
  1. +11
    -2
      src/core.h
  2. +7
    -1
      src/debug/quad.cpp
  3. +7
    -5
      src/log.h
  4. +32
    -14
      src/trig.cpp

+ 11
- 2
src/core.h View File

@@ -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"


+ 7
- 1
src/debug/quad.cpp View File

@@ -12,6 +12,12 @@
# include "config.h"
#endif

#ifdef WIN32
# define _USE_MATH_DEFINES /* for M_PI */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif

#include <cmath>
#include <cstdio>
#include <cstring>
@@ -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++)
{


+ 7
- 5
src/log.h View File

@@ -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
};



+ 32
- 14
src/trig.cpp View File

@@ -16,6 +16,8 @@
# include <fastmath.h>
#endif

#include <cmath>

#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;


Loading…
Cancel
Save