Split out some compiler-version-specific definitions into "compiler.h".

Split out 'getpixel' and 'putpixel' family of functions into "pixels.c" and "pixels.h" source files.
This commit is contained in:
William Kendrick 2006-02-18 08:42:23 +00:00
parent 410c156d16
commit 3b5f10c4fe
6 changed files with 374 additions and 284 deletions

57
src/compiler.h Normal file
View file

@ -0,0 +1,57 @@
#ifdef __GNUC__
// This version has strict type checking for safety.
// See the "unnecessary" pointer comparison. (from Linux)
#define min(x,y) ({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x < _y ? _x : _y; })
#define max(x,y) ({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x > _y ? _x : _y; })
#else
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#define clamp(lo,value,hi) (min(max(value,lo),hi))
// since gcc-2.5
#ifdef __GNUC__
#define NORETURN __attribute__((__noreturn__))
#define FUNCTION __attribute__((__const__)) // no access to global mem, even via ptr, and no side effect
#else
#define NORETURN
#define FUNCTION
#endif
#if !defined(restrict) && __STDC_VERSION__ < 199901
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92
#define restrict __restrict__
#else
#warning No restrict keyword?
#define restrict
#endif
#endif
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
// won't alias anything, and aligned enough for anything
#define MALLOC __attribute__ ((__malloc__))
// no side effect, may read globals
#define PURE __attribute__ ((__pure__))
// tell gcc what to expect: if(unlikely(err)) die(err);
#define likely(x) __builtin_expect(!!(x),1)
#define unlikely(x) __builtin_expect(!!(x),0)
#define expected(x,y) __builtin_expect((x),(y))
#else
#define MALLOC
#define PURE
#define likely(x) (x)
#define unlikely(x) (x)
#define expected(x,y) (x)
#endif