sysdep.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef CSOUND_SYSDEP_H
00025 #define CSOUND_SYSDEP_H
00026
00027
00028
00029 #ifdef HAVE_GCC3
00030 # undef HAVE_GCC3
00031 #endif
00032 #ifdef HAVE_C99
00033 # undef HAVE_C99
00034 #endif
00035 #if (defined(__GNUC__) && (__GNUC__ >= 3))
00036 # define HAVE_C99 1
00037 # if defined(__BUILDING_LIBCSOUND) || defined(CSOUND_CSDL_H)
00038 # ifndef _ISOC99_SOURCE
00039 # define _ISOC99_SOURCE 1
00040 # endif
00041 # ifndef _ISOC9X_SOURCE
00042 # define _ISOC9X_SOURCE 1
00043 # endif
00044 # endif
00045 # if !(defined(__MACH__) && (__GNUC__ == 3) && (__GNUC_MINOR__ < 2))
00046 # define HAVE_GCC3 1
00047 # endif
00048 #elif (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
00049 # define HAVE_C99 1
00050 #endif
00051
00052 #include <stdio.h>
00053 #include <stdlib.h>
00054 #include <math.h>
00055 #include <string.h>
00056 #if defined(HAVE_FCNTL_H) || defined(__unix) || defined(__unix__)
00057 #include <fcntl.h>
00058 #endif
00059 #if defined(HAVE_UNISTD_H) || defined(__unix) || defined(__unix__)
00060 #include <unistd.h>
00061 #endif
00062
00063
00064
00065 #ifndef __MYFLT_DEF
00066 # define __MYFLT_DEF
00067 # ifndef USE_DOUBLE
00068 # define MYFLT float
00069 # else
00070 # define MYFLT double
00071 # endif
00072 #endif
00073
00074 #if defined(__BUILDING_LIBCSOUND) || defined(CSOUND_CSDL_H)
00075
00076 #define FL(x) ((MYFLT) (x))
00077
00078
00079
00080 #if defined(_WIN32) || defined(__WIN32__)
00081 # ifndef WIN32
00082 # define WIN32 1
00083 # endif
00084 #elif (defined(linux) || defined(__linux)) && !defined(LINUX)
00085 # define LINUX 1
00086 #endif
00087
00088 #if defined(WIN32) && defined(_MSC_VER) && !defined(__GNUC__)
00089 # ifndef MSVC
00090 # define MSVC 1
00091 # endif
00092 #elif defined(MSVC)
00093 # undef MSVC
00094 #endif
00095
00096
00097
00098
00099 #if !(defined(__cplusplus) || defined(inline))
00100 # if defined(HAVE_C99) || defined(HAVE_GCC3)
00101 # if defined(__GNUC__) && defined(__STRICT_ANSI__)
00102 # define inline __inline__
00103 # endif
00104 # elif defined(MSVC)
00105 # define inline __inline
00106 # elif defined(__MWERKS__)
00107 # define inline inline
00108 # else
00109 # define inline
00110 # endif
00111 #endif
00112
00113 #if defined(macintosh)
00114 # define mac_classic
00115
00116
00117 # ifndef USE_GUSI2
00118 # include <stat.h>
00119 # endif
00120 # define O_NDELAY (0)
00121 # define DIRSEP ':'
00122 #elif defined(SYMANTEC)
00123 # include <unix.h>
00124 # define DIRSEP ':'
00125 #else
00126 # define DIRSEP '/'
00127 # ifdef LATTICE
00128 # ifdef HAVE_SYS_TYPES_H
00129 # include <sys/types.h>
00130 # endif
00131 # else
00132 # ifdef __WATCOMC__
00133 # if !defined(O_NDELAY)
00134 # define O_NDELAY (0)
00135 # endif
00136 # include <io.h>
00137 # else
00138 # ifdef WIN32
00139 # undef DIRSEP
00140 # define DIRSEP '\\'
00141 # if !defined(O_NDELAY)
00142 # define O_NDELAY (0)
00143 # endif
00144 # include <io.h>
00145 # else
00146 # ifdef DOSGCC
00147 # if !defined(O_NDELAY)
00148 # define O_NDELAY (0)
00149 # endif
00150 # endif
00151 # ifdef HAVE_SYS_TYPES_H
00152 # include <sys/types.h>
00153 # endif
00154 # endif
00155
00156 # ifndef MSVC
00157 # include <sys/file.h>
00158 # endif
00159 # endif
00160 # endif
00161 # include <sys/stat.h>
00162 #endif
00163
00164 #endif
00165
00166
00167
00168 #if defined(USE_GUSI2)
00169
00170
00171 typedef int64_t int_least64_t;
00172 typedef uint64_t uint_least64_t;
00173 #elif defined(HAVE_STDINT_H) || defined(HAVE_C99)
00174 # include <stdint.h>
00175 #else
00176 typedef signed char int8_t;
00177 typedef unsigned char uint8_t;
00178 typedef short int16_t;
00179 typedef unsigned short uint16_t;
00180 typedef int int32_t;
00181 typedef unsigned int uint32_t;
00182 # if defined(__GNUC__) || !defined(WIN32)
00183 typedef long long int64_t;
00184 typedef unsigned long long uint64_t;
00185 typedef long long int_least64_t;
00186 typedef unsigned long long uint_least64_t;
00187 # else
00188 typedef __int64 int64_t;
00189 typedef unsigned __int64 uint64_t;
00190 typedef __int64 int_least64_t;
00191 typedef unsigned __int64 uint_least64_t;
00192 # endif
00193 #if !defined(MSVC)
00194 typedef long intptr_t;
00195 typedef unsigned long uintptr_t;
00196 #endif
00197 #endif
00198
00199
00200
00201 #if defined(HAVE_GCC3) && !defined(SWIG)
00202
00203 # define CS_DEPRECATED __attribute__ ((__deprecated__))
00204
00205 # define CS_NOINLINE __attribute__ ((__noinline__))
00206
00207 # define CS_NORETURN __attribute__ ((__noreturn__))
00208
00209 # define CS_PRINTF1 __attribute__ ((__format__ (__printf__, 1, 2)))
00210
00211 # define CS_PRINTF2 __attribute__ ((__format__ (__printf__, 2, 3)))
00212
00213 # define CS_PRINTF3 __attribute__ ((__format__ (__printf__, 3, 4)))
00214
00215 # define CS_PURE __attribute__ ((__pure__))
00216 #else
00217 # define CS_DEPRECATED
00218 # define CS_NOINLINE
00219 # define CS_NORETURN
00220 # define CS_PRINTF1
00221 # define CS_PRINTF2
00222 # define CS_PRINTF3
00223 # define CS_PURE
00224 #endif
00225
00226 #if defined(__BUILDING_LIBCSOUND) || defined(CSOUND_CSDL_H)
00227
00228
00229
00230
00231
00232 #ifdef USE_LRINT
00233 # ifndef USE_DOUBLE
00234 # define MYFLT2LONG(x) ((long) lrintf((float) (x)))
00235 # define MYFLT2LRND(x) ((long) lrintf((float) (x)))
00236 # else
00237 # define MYFLT2LONG(x) ((long) lrint((double) (x)))
00238 # define MYFLT2LRND(x) ((long) lrint((double) (x)))
00239 # endif
00240 #elif defined(MSVC)
00241 # ifndef USE_DOUBLE
00242 static inline long MYFLT2LRND(float fval)
00243 {
00244 int result;
00245 _asm {
00246 fld fval
00247 fistp result
00248 mov eax, result
00249 }
00250 return result;
00251 }
00252 # else
00253 static inline long MYFLT2LRND(double fval)
00254 {
00255 int result;
00256 _asm {
00257 fld fval
00258 fistp result
00259 mov eax, result
00260 }
00261 return result;
00262 }
00263 # endif
00264 # define MYFLT2LONG(x) MYFLT2LRND(x)
00265 #else
00266 # ifndef USE_DOUBLE
00267 # define MYFLT2LONG(x) ((long) (x))
00268 # if defined(HAVE_GCC3) && defined(__i386__) && !defined(__ICC)
00269 # define MYFLT2LRND(x) ((long) lrintf((float) (x)))
00270 # else
00271 static inline long MYFLT2LRND(float fval)
00272 {
00273 return ((long) (fval + (fval < 0.0f ? -0.5f : 0.5f)));
00274 }
00275 # endif
00276 # else
00277 # define MYFLT2LONG(x) ((long) (x))
00278 # if defined(HAVE_GCC3) && defined(__i386__) && !defined(__ICC)
00279 # define MYFLT2LRND(x) ((long) lrint((double) (x)))
00280 # else
00281 static inline long MYFLT2LRND(double fval)
00282 {
00283 return ((long) (fval + (fval < 0.0 ? -0.5 : 0.5)));
00284 }
00285 # endif
00286 # endif
00287 #endif
00288
00289
00290
00291 #if defined(__i386__) || defined(MSVC)
00292 static inline float csoundUndenormalizeFloat(float x)
00293 {
00294 volatile float tmp = 1.0e-30f;
00295 return ((x + 1.0e-30f) - tmp);
00296 }
00297
00298 static inline double csoundUndenormalizeDouble(double x)
00299 {
00300 volatile double tmp = 1.0e-200;
00301 return ((x + 1.0e-200) - tmp);
00302 }
00303 #else
00304 # define csoundUndenormalizeFloat(x) x
00305 # define csoundUndenormalizeDouble(x) x
00306 #endif
00307
00308 #ifndef USE_DOUBLE
00309 # define csoundUndenormalizeMYFLT csoundUndenormalizeFloat
00310 #else
00311 # define csoundUndenormalizeMYFLT csoundUndenormalizeDouble
00312 #endif
00313
00314 #endif
00315
00316 #endif
00317