1
0
Fork 0

(svn r793) Merge INLINE -> inline replacement (revision 376)

release/0.4.5
tron 2004-11-24 13:19:48 +00:00
parent 0ea87b6473
commit fca55e3741
9 changed files with 50 additions and 51 deletions

View File

@ -11,20 +11,20 @@
#undef max #undef max
#endif #endif
static INLINE int min(int a, int b) { if (a <= b) return a; return b; } static inline int min(int a, int b) { if (a <= b) return a; return b; }
static INLINE int max(int a, int b) { if (a >= b) return a; return b; } static inline int max(int a, int b) { if (a >= b) return a; return b; }
static INLINE int64 max64(int64 a, int64 b) { if (a >= b) return a; return b; } static inline int64 max64(int64 a, int64 b) { if (a >= b) return a; return b; }
static INLINE uint minu(uint a, uint b) { if (a <= b) return a; return b; } static inline uint minu(uint a, uint b) { if (a <= b) return a; return b; }
static INLINE uint maxu(uint a, uint b) { if (a >= b) return a; return b; } static inline uint maxu(uint a, uint b) { if (a >= b) return a; return b; }
static INLINE int clamp(int a, int min, int max) { if (a <= min) return min; if (a >= max) return max; return a; } static inline int clamp(int a, int min, int max) { if (a <= min) return min; if (a >= max) return max; return a; }
static INLINE int clamp2(int a, int min, int max) { if (a <= min) a=min; if (a >= max) a=max; return a; } static inline int clamp2(int a, int min, int max) { if (a <= min) a=min; if (a >= max) a=max; return a; }
static INLINE bool int32_add_overflow(int32 a, int32 b) { return (int32)(a^b)>=0 && (int32)(a^(a+b))<0; } static inline bool int32_add_overflow(int32 a, int32 b) { return (int32)(a^b)>=0 && (int32)(a^(a+b))<0; }
static INLINE bool int32_sub_overflow(int32 a, int32 b) { return (int32)(a^b)<0 && (int32)(a^(a-b))<0; } static inline bool int32_sub_overflow(int32 a, int32 b) { return (int32)(a^b)<0 && (int32)(a^(a-b))<0; }
static INLINE bool str_eq(const byte *a, const byte *b) static inline bool str_eq(const byte *a, const byte *b)
{ {
int i=0; int i=0;
while (a[i] == b[i]) { while (a[i] == b[i]) {
@ -36,7 +36,7 @@ static INLINE bool str_eq(const byte *a, const byte *b)
} }
// Will crash if strings are equal // Will crash if strings are equal
static INLINE bool str_is_below(byte *a, byte *b) { static inline bool str_is_below(byte *a, byte *b) {
while (*a <= *b) { while (*a <= *b) {
if (*a < *b) return true; if (*a < *b) return true;
a++; a++;
@ -46,19 +46,19 @@ static INLINE bool str_is_below(byte *a, byte *b) {
} }
static INLINE int32 BIGMULSS(int32 a, int32 b, int shift) { static inline int32 BIGMULSS(int32 a, int32 b, int shift) {
return (int32)(((int64)(a) * (int64)(b)) >> (shift)); return (int32)(((int64)(a) * (int64)(b)) >> (shift));
} }
static INLINE int64 BIGMULSS64(int64 a, int64 b, int shift) { static inline int64 BIGMULSS64(int64 a, int64 b, int shift) {
return ((a) * (b)) >> (shift); return ((a) * (b)) >> (shift);
} }
static INLINE uint32 BIGMULUS(uint32 a, uint32 b, int shift) { static inline uint32 BIGMULUS(uint32 a, uint32 b, int shift) {
return (uint32)(((uint64)(a) * (uint64)(b)) >> (shift)); return (uint32)(((uint64)(a) * (uint64)(b)) >> (shift));
} }
static INLINE int64 BIGMULS(int32 a, int32 b) { static inline int64 BIGMULS(int32 a, int32 b) {
return (int32)(((int64)(a) * (int64)(b))); return (int32)(((int64)(a) * (int64)(b)));
} }
@ -145,7 +145,7 @@ extern const byte _ffb_64[128];
*/ */
#define KILL_FIRST_BIT(x) _ffb_64[(x)+64] #define KILL_FIRST_BIT(x) _ffb_64[(x)+64]
static INLINE int FindFirstBit2x64(int value) static inline int FindFirstBit2x64(int value)
{ {
int i = 0; int i = 0;
if ( (byte) value == 0) { if ( (byte) value == 0) {
@ -195,17 +195,17 @@ static INLINE int FindFirstBit2x64(int value)
#define abs myabs #define abs myabs
static INLINE int intxchg_(int *a, int b) { int t = *a; *a = b; return t; } static inline int intxchg_(int *a, int b) { int t = *a; *a = b; return t; }
#define intxchg(a,b) intxchg_(&(a), (b)) #define intxchg(a,b) intxchg_(&(a), (b))
#define intswap(a,b) ((b) = intxchg_(&(a), (b))) #define intswap(a,b) ((b) = intxchg_(&(a), (b)))
static INLINE int myabs(int a) { if (a<0) a = -a; return a; } static inline int myabs(int a) { if (a<0) a = -a; return a; }
static INLINE int64 myabs64(int64 a) { if (a<0) a = -a; return a; } static inline int64 myabs64(int64 a) { if (a<0) a = -a; return a; }
static INLINE void swap_byte(byte *a, byte *b) { byte t = *a; *a = *b; *b = t; } static inline void swap_byte(byte *a, byte *b) { byte t = *a; *a = *b; *b = t; }
static INLINE void swap_uint16(uint16 *a, uint16 *b) { uint16 t = *a; *a = *b; *b = t; } static inline void swap_uint16(uint16 *a, uint16 *b) { uint16 t = *a; *a = *b; *b = t; }
static INLINE void swap_int16(int16 *a, int16 *b) { int16 t = *a; *a = *b; *b = t; } static inline void swap_int16(int16 *a, int16 *b) { int16 t = *a; *a = *b; *b = t; }
static INLINE void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a = *b; *b = t; } static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a = *b; *b = t; }
@ -214,14 +214,14 @@ static INLINE void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a
# define ADD_WORD(x) (x)&0xFF, ((x) >> 8)&0xFF # define ADD_WORD(x) (x)&0xFF, ((x) >> 8)&0xFF
# define ADD_DWORD(x) (x)&0xFF, ((x) >> 8)&0xFF, ((x) >> 16)&0xFF, ((x) >> 24)&0xFF # define ADD_DWORD(x) (x)&0xFF, ((x) >> 8)&0xFF, ((x) >> 16)&0xFF, ((x) >> 24)&0xFF
#elif defined(TTD_BIG_ENDIAN) #elif defined(TTD_BIG_ENDIAN)
static INLINE uint16 READ_LE_UINT16(const void *b) { static inline uint16 READ_LE_UINT16(const void *b) {
return ((const byte*)b)[0] + (((const byte*)b)[1] << 8); return ((const byte*)b)[0] + (((const byte*)b)[1] << 8);
} }
# define ADD_WORD(x) ((x) >> 8)&0xFF, (x)&0xFF # define ADD_WORD(x) ((x) >> 8)&0xFF, (x)&0xFF
# define ADD_DWORD(x) ((x) >> 24)&0xFF, ((x) >> 16)&0xFF, ((x) >> 8)&0xFF, (x)&0xFF # define ADD_DWORD(x) ((x) >> 24)&0xFF, ((x) >> 16)&0xFF, ((x) >> 8)&0xFF, (x)&0xFF
#endif #endif
static INLINE void WRITE_LE_UINT16(void *b, uint16 x) { static inline void WRITE_LE_UINT16(void *b, uint16 x) {
((byte*)b)[0] = (byte)x; ((byte*)b)[0] = (byte)x;
((byte*)b)[1] = (byte)(x >> 8); ((byte*)b)[1] = (byte)(x >> 8);
} }

2
misc.c
View File

@ -10,7 +10,7 @@ extern void InitNewsItemStructs();
byte _name_array[512][32]; byte _name_array[512][32];
static INLINE uint32 ROR(uint32 x, int n) static inline uint32 ROR(uint32 x, int n)
{ {
return (x >> n) + (x << ((sizeof(x)*8)-n)); return (x >> n) + (x << ((sizeof(x)*8)-n));
} }

View File

@ -114,7 +114,7 @@ do { \
} while (0) } while (0)
static byte INLINE grf_load_byte(byte **buf) static inline byte grf_load_byte(byte **buf)
{ {
return *(*buf)++; return *(*buf)++;
} }

View File

@ -434,7 +434,7 @@ typedef struct {
// called after a new element was added in the queue at the last index. // called after a new element was added in the queue at the last index.
// move it down to the proper position // move it down to the proper position
static void INLINE HeapifyUp(NewTrackPathFinder *tpf) static void inline HeapifyUp(NewTrackPathFinder *tpf)
{ {
StackedItem si; StackedItem si;
int i = ++tpf->nstack; int i = ++tpf->nstack;
@ -448,7 +448,7 @@ static void INLINE HeapifyUp(NewTrackPathFinder *tpf)
} }
// called after the element 0 was eaten. fill it with a new element // called after the element 0 was eaten. fill it with a new element
static void INLINE HeapifyDown(NewTrackPathFinder *tpf) static void inline HeapifyDown(NewTrackPathFinder *tpf)
{ {
StackedItem si; StackedItem si;
int i = 1, j; int i = 1, j;

View File

@ -173,22 +173,22 @@ static uint SlGetGammaLength(uint i) {
return (i>=0x80) ? 2 : 1; return (i>=0x80) ? 2 : 1;
} }
int INLINE SlReadSparseIndex() int inline SlReadSparseIndex()
{ {
return SlReadSimpleGamma(); return SlReadSimpleGamma();
} }
void INLINE SlWriteSparseIndex(uint index) void inline SlWriteSparseIndex(uint index)
{ {
SlWriteSimpleGamma(index); SlWriteSimpleGamma(index);
} }
int INLINE SlReadArrayLength() int inline SlReadArrayLength()
{ {
return SlReadSimpleGamma(); return SlReadSimpleGamma();
} }
void INLINE SlWriteArrayLength(uint length) void inline SlWriteArrayLength(uint length)
{ {
SlWriteSimpleGamma(length); SlWriteSimpleGamma(length);
} }

View File

@ -221,7 +221,7 @@ static const uint16 * const _legend_table[] = {
}; };
#if defined(TTD_ALIGNMENT_4) #if defined(TTD_ALIGNMENT_4)
static INLINE void WRITE_PIXELS(void *dst, uint32 val) static inline void WRITE_PIXELS(void *dst, uint32 val)
{ {
byte *d = (byte*)dst; byte *d = (byte*)dst;
# if defined(TTD_BIG_ENDIAN) # if defined(TTD_BIG_ENDIAN)
@ -238,7 +238,7 @@ static const uint16 * const _legend_table[] = {
} }
/* need to use OR, otherwise we will overwrite the wrong pixels at the edges :( */ /* need to use OR, otherwise we will overwrite the wrong pixels at the edges :( */
static INLINE void WRITE_PIXELS_OR(void *dst, uint32 val) static inline void WRITE_PIXELS_OR(void *dst, uint32 val)
{ {
byte *d = (byte*)dst; byte *d = (byte*)dst;
# if defined(TTD_BIG_ENDIAN) # if defined(TTD_BIG_ENDIAN)
@ -328,7 +328,7 @@ static const uint32 _smallmap_vegetation_andor[12][2] = {
{MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)}, {MKCOLOR(0x00D7D700),MKCOLOR(0xFF0000FF)},
}; };
static uint32 INLINE GetSmallMapCountoursPixels(uint tile) static inline uint32 GetSmallMapCountoursPixels(uint tile)
{ {
uint t; uint t;
@ -358,7 +358,7 @@ static void DrawSmallMapContours(byte *dst, uint xc, uint yc, int pitch, int rep
} }
static uint32 INLINE GetSmallMapVehiclesPixels(uint tile) static inline uint32 GetSmallMapVehiclesPixels(uint tile)
{ {
uint t; uint t;
@ -411,7 +411,7 @@ static const byte _industry_smallmap_colors[175] = {
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
}; };
static uint32 INLINE GetSmallMapIndustriesPixels(uint tile) static inline uint32 GetSmallMapIndustriesPixels(uint tile)
{ {
int t; int t;
@ -443,7 +443,7 @@ static void DrawSmallMapIndustries(byte *dst, uint xc, uint yc, int pitch, int r
} while (xc++,yc++,dst+=pitch,--reps != 0); } while (xc++,yc++,dst+=pitch,--reps != 0);
} }
static uint32 INLINE GetSmallMapRoutesPixels(uint tile) static inline uint32 GetSmallMapRoutesPixels(uint tile)
{ {
int t; int t;
uint32 bits; uint32 bits;
@ -499,7 +499,7 @@ static const uint32 _vegetation_clear_bits[4 + 7] = {
MKCOLOR(0x54545454), MKCOLOR(0x54545454),
}; };
static uint32 INLINE GetSmallMapVegetationPixels(uint tile) static inline uint32 GetSmallMapVegetationPixels(uint tile)
{ {
int i,t; int i,t;
uint32 bits; uint32 bits;
@ -545,7 +545,7 @@ static void DrawSmallMapVegetation(byte *dst, uint xc, uint yc, int pitch, int r
static uint32 *_owner_colors; static uint32 *_owner_colors;
static uint32 INLINE GetSmallMapOwnerPixels(uint tile) static inline uint32 GetSmallMapOwnerPixels(uint tile)
{ {
int t; int t;
@ -601,7 +601,7 @@ static const byte _vehicle_type_colors[6] = {
184, 191, 152, 15, 215, 184 184, 191, 152, 15, 215, 184
}; };
static INLINE uint32 dup_byte32(byte b) { static inline uint32 dup_byte32(byte b) {
return b + (b << 8) + (b << 16) + (b << 24); return b + (b << 8) + (b << 16) + (b << 24);
} }

View File

@ -2119,7 +2119,7 @@ static void ClickTile_Station(uint tile)
} }
} }
static INLINE bool IsTrainStationTile(uint tile) { static inline bool IsTrainStationTile(uint tile) {
return IS_TILETYPE(tile, MP_STATION) && IS_BYTE_INSIDE(_map5[tile], 0, 8); return IS_TILETYPE(tile, MP_STATION) && IS_BYTE_INSIDE(_map5[tile], 0, 8);
} }
@ -2233,7 +2233,7 @@ static void StationHandleBigTick(Station *st)
} }
} }
static INLINE void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; } static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; }
static byte _rating_boost[3] = { 0, 31, 63}; static byte _rating_boost[3] = { 0, 31, 63};

View File

@ -43,7 +43,6 @@
#if defined(__GNUC__) #if defined(__GNUC__)
# define NORETURN # define NORETURN
# define FORCEINLINE inline # define FORCEINLINE inline
# define INLINE inline
# define CDECL # define CDECL
//#include <alloca.h> //#include <alloca.h>
//#include <malloc.h> //#include <malloc.h>
@ -62,7 +61,7 @@
# include <malloc.h> // alloca() # include <malloc.h> // alloca()
# define NORETURN __declspec(noreturn) # define NORETURN __declspec(noreturn)
# define FORCEINLINE __forceinline # define FORCEINLINE __forceinline
# define INLINE _inline # define inline _inline
# define CDECL _cdecl # define CDECL _cdecl
# define NOT_REACHED() _assume(0) # define NOT_REACHED() _assume(0)
# define snprintf _snprintf # define snprintf _snprintf
@ -116,10 +115,10 @@ typedef unsigned __int64 uint64;
# define TTD_ALIGNMENT_2 # define TTD_ALIGNMENT_2
# define TTD_ALIGNMENT_4 # define TTD_ALIGNMENT_4
static uint32 INLINE TO_LE32(uint32 x) { return BSWAP32(x); } static inline uint32 TO_LE32(uint32 x) { return BSWAP32(x); }
static uint16 INLINE TO_LE16(uint16 x) { return BSWAP16(x); } static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); }
static uint32 INLINE FROM_LE32(uint32 x) { return BSWAP32(x); } static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); }
static uint16 INLINE FROM_LE16(uint16 x) { return BSWAP16(x); } static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); }
#define TO_BE32(x) x #define TO_BE32(x) x
#define TO_BE16(x) x #define TO_BE16(x) x
#define FROM_BE32(x) x #define FROM_BE32(x) x

View File

@ -1227,7 +1227,7 @@ static void ViewportDrawChk(ViewPort *vp, int left, int top, int right, int bott
} }
} }
static void INLINE ViewportDraw(ViewPort *vp, int left, int top, int right, int bottom) static inline void ViewportDraw(ViewPort *vp, int left, int top, int right, int bottom)
{ {
int t; int t;