Changeset 905


Ignore:
Timestamp:
Sep 5, 2011, 7:18:06 PM (8 years ago)
Author:
sam
Message:

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

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core.h

    r899 r905  
    2626
    2727// Optimisation helpers
    28 #define __likely(x)   __builtin_expect(!!(x), 1)
    29 #define __unlikely(x) __builtin_expect(!!(x), 0)
     28#if defined __GNUC__
     29#   define __likely(x)   __builtin_expect(!!(x), 1)
     30#   define __unlikely(x) __builtin_expect(!!(x), 0)
     31#   define INLINEATTR __attribute__((always_inline))
     32#   define FP_USE(x) __asm__("" : "+m" (x))
     33#else
     34#   define __likely(x)   x
     35#   define __unlikely(x) x
     36#   define INLINEATTR
     37#   define FP_USE(x) (void)(x)
     38#endif
    3039
    3140// Base types
  • trunk/src/debug/quad.cpp

    r904 r905  
    1111#if defined HAVE_CONFIG_H
    1212#   include "config.h"
     13#endif
     14
     15#ifdef WIN32
     16#   define _USE_MATH_DEFINES /* for M_PI */
     17#   define WIN32_LEAN_AND_MEAN
     18#   include <windows.h>
    1319#endif
    1420
     
    8389     * between consecutive points. */
    8490    static int const SINE_SIZE = 256;
    85     static float const SINE_SPACE = 0.01f;
    8691    GLfloat const *GetSineArray()
    8792    {
     93        static float const SINE_SPACE = 0.01f;
    8894        float x = 0.0f;
    8995        for (npoints = 0; npoints < SINE_SIZE && x <= 1.0f; npoints++)
  • trunk/src/log.h

    r748 r905  
    2727public:
    2828#ifdef __GNUC__
    29 #   define LOL_FMT_ATTR __attribute__((format(printf, 1, 2)))
     29#   define LOL_FMT_ATTR(n, p) __attribute__((format(printf, n, p)))
     30#else
     31#   define LOL_FMT_ATTR(n, p)
    3032#endif
    31     static void Debug(char const *format, ...) LOL_FMT_ATTR;
    32     static void Info(char const *format, ...) LOL_FMT_ATTR;
    33     static void Warn(char const *format, ...) LOL_FMT_ATTR;
    34     static void Error(char const *format, ...) LOL_FMT_ATTR;
     33    static void Debug(char const *format, ...) LOL_FMT_ATTR(1, 2);
     34    static void Info(char const *format, ...) LOL_FMT_ATTR(1, 2);
     35    static void Warn(char const *format, ...) LOL_FMT_ATTR(1, 2);
     36    static void Error(char const *format, ...) LOL_FMT_ATTR(1, 2);
    3537#undef LOL_FMT_ATTR
    3638};
  • trunk/src/trig.cpp

    r902 r905  
    1717#endif
    1818
     19#include <cmath>
     20
    1921#include "core.h"
    2022
     
    3739static const double QUARTER = 0.25;
    3840static const double TWO     = 2.0;
     41#if defined __GNUC__
    3942static const double VERY_SMALL_NUMBER = 0x1.0p-128;
     43#else
     44static const double VERY_SMALL_NUMBER = 3e-39;
     45#endif
    4046static const double TWO_EXP_52 = 4503599627370496.0;
    4147static const double TWO_EXP_54 = 18014398509481984.0;
     
    8995
    9096/* Custom intrinsics */
    91 #define INLINEATTR __attribute__((always_inline))
     97#if defined __GNUC__
     98#   define INLINEATTR __attribute__((always_inline))
     99#   define FP_USE(x) __asm__("" : "+m" (x))
     100#else
     101#   define INLINEATTR
     102#   define FP_USE(x) (void)(x)
     103#endif
    92104
    93105#if defined __CELLOS_LV2__
     
    101113#endif
    102114static inline double lol_fabs(double x) INLINEATTR;
     115#if defined __GNUC__
    103116static inline double lol_round(double x) INLINEATTR;
    104117static inline double lol_trunc(double x) INLINEATTR;
     118#endif
    105119
    106120#if defined __CELLOS_LV2__
     
    201215             : "=f" (r) : "f" (x));
    202216    return r;
    203 #else
     217#elif defined __GNUC__
    204218    return __builtin_fabs(x);
    205 #endif
    206 }
    207 
     219#else
     220    return fabs(x);
     221#endif
     222}
     223
     224#if defined __GNUC__
    208225static inline double lol_round(double x)
    209226{
     
    223240#endif
    224241}
     242#endif
    225243
    226244double lol_sin(double x)
     
    254272#else
    255273    double num_cycles = absx + TWO_EXP_52;
    256     __asm__("" : "+m" (num_cycles)); num_cycles -= TWO_EXP_52;
     274    FP_USE(num_cycles); num_cycles -= TWO_EXP_52;
    257275
    258276    double is_even = TWO * num_cycles - ONE;
    259     __asm__("" : "+m" (is_even)); is_even += TWO_EXP_54;
    260     __asm__("" : "+m" (is_even)); is_even -= TWO_EXP_54;
    261     __asm__("" : "+m" (is_even));
     277    FP_USE(is_even); is_even += TWO_EXP_54;
     278    FP_USE(is_even); is_even -= TWO_EXP_54;
     279    FP_USE(is_even);
    262280    is_even -= TWO * num_cycles - ONE;
    263281    double sign = is_even;
     
    322340#else
    323341    double num_cycles = absx + TWO_EXP_52;
    324     __asm__("" : "+m" (num_cycles)); num_cycles -= TWO_EXP_52;
     342    FP_USE(num_cycles); num_cycles -= TWO_EXP_52;
    325343
    326344    double is_even = TWO * num_cycles - ONE;
    327     __asm__("" : "+m" (is_even)); is_even += TWO_EXP_54;
    328     __asm__("" : "+m" (is_even)); is_even -= TWO_EXP_54;
    329     __asm__("" : "+m" (is_even));
     345    FP_USE(is_even); is_even += TWO_EXP_54;
     346    FP_USE(is_even); is_even -= TWO_EXP_54;
     347    FP_USE(is_even);
    330348    is_even -= TWO * num_cycles - ONE;
    331349    double sign = is_even;
     
    397415#else
    398416    double num_cycles = absx + TWO_EXP_52;
    399     __asm__("" : "+m" (num_cycles)); num_cycles -= TWO_EXP_52;
     417    FP_USE(num_cycles); num_cycles -= TWO_EXP_52;
    400418
    401419    double is_even = TWO * num_cycles - ONE;
    402     __asm__("" : "+m" (is_even)); is_even += TWO_EXP_54;
    403     __asm__("" : "+m" (is_even)); is_even -= TWO_EXP_54;
    404     __asm__("" : "+m" (is_even));
     420    FP_USE(is_even); is_even += TWO_EXP_54;
     421    FP_USE(is_even); is_even -= TWO_EXP_54;
     422    FP_USE(is_even);
    405423    is_even -= TWO * num_cycles - ONE;
    406424    double sin_sign = is_even;
Note: See TracChangeset for help on using the changeset viewer.