]>
Commit | Line | Data |
---|---|---|
578bfd0a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
1ae93c94 | 3 | // $Id: system.h,v 1.3 1999/12/10 23:40:29 jgg Exp $ |
578bfd0a AL |
4 | /* ###################################################################### |
5 | ||
6 | System Header - Usefull private definitions | |
7 | ||
8 | This source is placed in the Public Domain, do with it what you will | |
9 | It was originally written by Brian C. White. | |
10 | ||
11 | ##################################################################### */ | |
12 | /*}}}*/ | |
13 | // Private header | |
578bfd0a AL |
14 | #ifndef SYSTEM_H |
15 | #define SYSTEM_H | |
16 | ||
17 | // MIN_VAL(SINT16) will return -0x8000 and MAX_VAL(SINT16) = 0x7FFF | |
18 | #define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) ))) | |
19 | #define MAX_VAL(t) (((t)(-1) > 0) ? (t)(-1) : (t)(((1L<<(sizeof(t)*8-1))-1))) | |
20 | ||
21 | // Min/Max functions | |
1ae93c94 | 22 | #if !defined(MIN) |
578bfd0a AL |
23 | #if defined(__HIGHC__) |
24 | #define MIN(x,y) _min(x,y) | |
25 | #define MAX(x,y) _max(x,y) | |
26 | #endif | |
27 | ||
28 | // GNU C++ has a min/max operator <coolio> | |
29 | #if defined(__GNUG__) | |
30 | #define MIN(A,B) ((A) <? (B)) | |
31 | #define MAX(A,B) ((A) >? (B)) | |
32 | #endif | |
33 | ||
34 | /* Templates tend to mess up existing code that uses min/max because of the | |
35 | strict matching requirements */ | |
36 | #if !defined(MIN) | |
37 | #define MIN(A,B) ((A) < (B)?(A):(B)) | |
38 | #define MAX(A,B) ((A) > (B)?(A):(B)) | |
39 | #endif | |
1ae93c94 | 40 | #endif |
578bfd0a AL |
41 | |
42 | /* Bound functions, bound will return the value b within the limits a-c | |
43 | bounv will change b so that it is within the limits of a-c. */ | |
44 | #define _bound(a,b,c) MIN(c,MAX(b,a)) | |
45 | #define _boundv(a,b,c) b = _bound(a,b,c) | |
46 | #define ABS(a) (((a) < (0)) ?-(a) : (a)) | |
47 | ||
48 | /* Usefull count macro, use on an array of things and it will return the | |
49 | number of items in the array */ | |
50 | #define _count(a) (sizeof(a)/sizeof(a[0])) | |
51 | ||
52 | // Flag Macros | |
53 | #define FLAG(f) (1L << (f)) | |
54 | #define SETFLAG(v,f) ((v) |= FLAG(f)) | |
55 | #define CLRFLAG(v,f) ((v) &=~FLAG(f)) | |
56 | #define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false) | |
57 | ||
7d15572b DK |
58 | // some nice optional GNUC features |
59 | #if __GNUC__ >= 3 | |
60 | #define __must_check __attribute__ ((warn_unused_result)) | |
61 | #define __deprecated __attribute__ ((deprecated)) | |
62 | /* likely() and unlikely() can be used to mark boolean expressions | |
63 | as (not) likely true which will help the compiler to optimise */ | |
64 | #define likely(x) __builtin_expect (!!(x), 1) | |
65 | #define unlikely(x) __builtin_expect (!!(x), 0) | |
66 | #else | |
67 | #define __must_check /* no warn_unused_result */ | |
68 | #define __deprecated /* no deprecated */ | |
69 | #define likely(x) (x) | |
70 | #define unlikely(x) (x) | |
71 | #endif | |
72 | ||
73 | // cold functions are unlikely() to be called | |
74 | #if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4 | |
75 | #define __cold __attribute__ ((__cold__)) | |
76 | #else | |
77 | #define __cold /* no cold marker */ | |
78 | #endif | |
79 | ||
578bfd0a | 80 | #endif |