--- rxvt-unicode/src/rxvtutil.h 2006/01/22 00:36:59 1.19 +++ rxvt-unicode/src/rxvtutil.h 2006/01/29 22:30:21 1.23 @@ -9,6 +9,9 @@ #define PP_STRINGIFY_(a) #a #define PP_STRINGIFY(a) PP_STRINGIFY_(a) +// actually, some gcc-3.x versions work, too +#define HAVE_GCC_BUILTINS (__GNUC__ >= 4) + extern class byteorder { static unsigned int e; // at least 32 bits public: @@ -31,6 +34,24 @@ template static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } +// linear interpolation +template +static inline +T lerp (T a, U b, P p) +{ + return (int(a) * int(p) + int(b) * int(100 - p)) / 100; +} + +// some bit functions, xft fuck me plenty +#if HAVE_GCC_BUILTINS +static inline int ctz (unsigned int x) { return __builtin_ctz (x); } +static inline int popcount (unsigned int x) { return __builtin_popcount (x); } +#else +// count trailing zero bits and count # of one bits +int ctz (unsigned int x); +int popcount (unsigned int x); +#endif + // in range including end #define IN_RANGE_INC(val,beg,end) \ ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) @@ -398,5 +419,15 @@ } }; +// return a very temporary (and never deallocated) buffer. keep small. +void *rxvt_temp_buf (int len); + +template +inline T * +rxvt_temp_buf (int len) +{ + return (T *)rxvt_temp_buf (len * sizeof (T)); +} + #endif