Merge remote-tracking branch 'mattst88/for-keith'

This commit is contained in:
Keith Packard
2011-09-21 14:34:27 -07:00
121 changed files with 3244 additions and 4203 deletions

View File

@@ -122,13 +122,19 @@ typedef struct _xReq *xReqPtr;
/* byte swap a 32-bit literal */
#define lswapl(x) ((((x) & 0xff) << 24) |\
(((x) & 0xff00) << 8) |\
(((x) & 0xff0000) >> 8) |\
(((x) >> 24) & 0xff))
static inline uint32_t lswapl(uint32_t x)
{
return ((x & 0xff) << 24) |
((x & 0xff00) << 8) |
((x & 0xff0000) >> 8) |
((x >> 24) & 0xff);
}
/* byte swap a short literal */
#define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
/* byte swap a 16-bit literal */
static inline uint16_t lswaps(uint16_t x)
{
return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
}
#undef min
#undef max
@@ -139,9 +145,6 @@ typedef struct _xReq *xReqPtr;
* it in case we haven't done that yet.
*/
#include <stdlib.h>
#ifndef Fabs
#define Fabs(a) ((a) > 0.0 ? (a) : -(a)) /* floating absolute value */
#endif
#define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
/* this assumes b > 0 */
#define modulus(a, b, d) if (((d) = (a) % (b)) < 0) (d) += (b)
@@ -258,32 +261,69 @@ version_compare(uint16_t a_major, uint16_t a_minor,
#define SwapRestL(stuff) \
SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
/* byte swap a 32-bit value */
#define swapl(x, n) { \
n = ((char *) (x))[0];\
((char *) (x))[0] = ((char *) (x))[3];\
((char *) (x))[3] = n;\
n = ((char *) (x))[1];\
((char *) (x))[1] = ((char *) (x))[2];\
((char *) (x))[2] = n; }
#ifdef __GNUC__
void __attribute__((error("wrong sized variable passed to swap"))) wrong_size(void);
#else
static inline void wrong_size(void)
{
}
/* byte swap a short */
#define swaps(x, n) { \
n = ((char *) (x))[0];\
((char *) (x))[0] = ((char *) (x))[1];\
((char *) (x))[1] = n; }
static inline void __builtin_constant_p(int x)
{
return 0;
}
#endif
/* byte swap a 32-bit value */
static inline void swap_uint32(uint32_t *x)
{
char n = ((char *) &x)[0];
((char *) x)[0] = ((char *) x)[3];
((char *) x)[3] = n;
n = ((char *) x)[1];
((char *) x)[1] = ((char *) x)[2];
((char *) x)[2] = n;
}
#define swapl(x) do { \
if (sizeof(*(x)) != 4) \
wrong_size(); \
if (__builtin_constant_p((uintptr_t)(x) & 3) && ((uintptr_t)(x) & 3) == 0) \
*(x) = lswapl(*(x)); \
else \
swap_uint32((uint32_t *)(x)); \
} while (0)
/* byte swap a 16-bit value */
static inline void swap_uint16(uint16_t *x)
{
char n = ((char *) x)[0];
((char *) x)[0] = ((char *) x)[1];
((char *) x)[1] = n;
}
#define swaps(x) do { \
if (sizeof(*(x)) != 2) \
wrong_size(); \
if (__builtin_constant_p((uintptr_t)(x) & 1) && ((uintptr_t)(x) & 1) == 0) \
*(x) = lswaps(*(x)); \
else \
swap_uint16((uint16_t *)(x)); \
} while (0)
/* copy 32-bit value from src to dst byteswapping on the way */
#define cpswapl(src, dst) { \
((char *)&(dst))[0] = ((char *) &(src))[3];\
((char *)&(dst))[1] = ((char *) &(src))[2];\
((char *)&(dst))[2] = ((char *) &(src))[1];\
((char *)&(dst))[3] = ((char *) &(src))[0]; }
#define cpswapl(src, dst) do { \
if (sizeof((src)) != 4 || sizeof((dst)) != 4) \
wrong_size(); \
(dst) = lswapl((src)); \
} while (0)
/* copy short from src to dst byteswapping on the way */
#define cpswaps(src, dst) { \
((char *) &(dst))[0] = ((char *) &(src))[1];\
((char *) &(dst))[1] = ((char *) &(src))[0]; }
#define cpswaps(src, dst) do { \
if (sizeof((src)) != 2 || sizeof((dst)) != 2) \
wrong_size(); \
(dst) = lswaps((src)); \
} while (0)
extern _X_EXPORT void SwapLongs(
CARD32 *list,