Make GLX byteswap macros more portable

- Use autoconf tests instead of platform-specific #ifdef's to decide
  which macros to use.
- Provide fallbacks for platforms like Solaris that don't provide any
  of the existing known forms.
This commit is contained in:
Alan Coopersmith 2007-01-03 15:44:55 -08:00
parent 66fa87292e
commit 2fd4626fa6
7 changed files with 146 additions and 45 deletions

View File

@ -25,21 +25,29 @@
* SOFTWARE.
*/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <X11/Xmd.h>
#include <GL/gl.h>
#include <GL/glxproto.h>
#if defined(__linux__) || defined (__GLIBC__) || defined(__GNU__)
#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#elif defined(__OpenBSD__)
#elif defined(USE_SYS_ENDIAN_H)
#include <sys/endian.h>
#define bswap_16 __swap16
#define bswap_32 __swap32
#define bswap_64 __swap64
#else
#include <sys/endian.h>
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#define bswap_16(value) \
((((value) & 0xff) << 8) | ((value) >> 8))
#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))
#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
<< 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
#endif
#include <inttypes.h>
#include "indirect_size.h"

View File

@ -46,18 +46,22 @@
#include "dispatch.h"
#include "glapioffsets.h"
#if defined(__linux__) || defined (__GLIBC__) || defined (__GNU__)
#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#elif defined(__OpenBSD__)
#elif defined(USE_SYS_ENDIAN_H)
#include <sys/endian.h>
#define bswap_16 __swap16
#define bswap_32 __swap32
#define bswap_64 __swap64
#else
#include <sys/endian.h>
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#define bswap_16(value) \
((((value) & 0xff) << 8) | ((value) >> 8))
#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))
#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
<< 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
#endif
static int DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte *pc,

View File

@ -39,18 +39,22 @@
#include "glthread.h"
#include "dispatch.h"
#if defined(__linux__) || defined (__GLIBC__) || defined (__GNU__)
#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#elif defined(__OpenBSD__)
#elif defined(USE_SYS_ENDIAN_H)
#include <sys/endian.h>
#define bswap_16 __swap16
#define bswap_32 __swap32
#define bswap_64 __swap64
#else
#include <sys/endian.h>
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#define bswap_16(value) \
((((value) & 0xff) << 8) | ((value) >> 8))
#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))
#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
<< 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
#endif
int __glXDisp_GetCompressedTexImageARB(struct __GLXclientStateRec *cl, GLbyte *pc)

View File

@ -23,23 +23,31 @@
* SOFTWARE.
*/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <string.h>
#include <X11/Xmd.h>
#include <GL/gl.h>
#include <GL/glxproto.h>
#if defined(__linux__) || defined (__GLIBC__) || defined(__GNU__)
#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#elif defined(__OpenBSD__)
#elif defined(USE_SYS_ENDIAN_H)
#include <sys/endian.h>
#define bswap_16 __swap16
#define bswap_32 __swap32
#define bswap_64 __swap64
#else
#include <sys/endian.h>
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#define bswap_16(value) \
((((value) & 0xff) << 8) | ((value) >> 8))
#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))
#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
<< 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
#endif
#include <inttypes.h>
#include "indirect_size.h"

View File

@ -40,18 +40,22 @@
#include "dispatch.h"
#include "glapioffsets.h"
#if defined(__linux__) || defined (__GLIBC__) || defined (__GNU__)
#if defined(HAVE_BYTESWAP_H)
#include <byteswap.h>
#elif defined(__OpenBSD__)
#elif defined(USE_SYS_ENDIAN_H)
#include <sys/endian.h>
#define bswap_16 __swap16
#define bswap_32 __swap32
#define bswap_64 __swap64
#else
#include <sys/endian.h>
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#define bswap_16(value) \
((((value) & 0xff) << 8) | ((value) >> 8))
#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))
#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
<< 32) | \
(uint64_t)bswap_32((uint32_t)((value) >> 32)))
#endif
static int DoSwapInterval(__GLXclientState *cl, GLbyte *pc, int do_swap);

View File

@ -99,6 +99,64 @@ fi
AC_TYPE_PID_T
# Checks for headers/macros for byte swapping
# Known variants:
# <byteswap.h> bswap_16, bswap_32, bswap_64 (glibc)
# <sys/endian.h> __swap16, __swap32, __swap64 (OpenBSD)
# <sys/endian.h> bswap16, bswap32, bswap64 (other BSD's)
# and a fallback to local macros if none of the above are found
# if <byteswap.h> is found, assume it's the correct version
AC_CHECK_HEADERS([byteswap.h])
# if <sys/endian.h> is found, have to check which version
AC_CHECK_HEADER([sys/endian.h], [HAVE_SYS_ENDIAN_H="yes"], [HAVE_SYS_ENDIAN_H="no"])
if test "x$HAVE_SYS_ENDIAN_H" = "xyes" ; then
AC_MSG_CHECKING([for __swap16 variant of <sys/endian.h> byteswapping macros])
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <sys/endian.h>
], [
int a = 1, b;
b = __swap16(a);
])
], [SYS_ENDIAN__SWAP='yes'], [SYS_ENDIAN__SWAP='no'])
AC_MSG_RESULT([$SYS_ENDIAN__SWAP])
AC_MSG_CHECKING([for bswap_16 variant of <sys/endian.h> byteswapping macros])
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <sys/endian.h>
], [
int a = 1, b;
b = bswap_16(a);
])
], [SYS_ENDIAN_BSWAP='yes'], [SYS_ENDIAN_BSWAP='no'])
AC_MSG_RESULT([$SYS_ENDIAN_BSWAP])
if test "$SYS_ENDIAN_BSWAP" = "yes" ; then
USE_SYS_ENDIAN_H=yes
BSWAP=bswap_
else
if test "$SYS_ENDIAN__SWAP" = "yes" ; then
USE_SYS_ENDIAN_H=yes
BSWAP=__swap
else
USE_SYS_ENDIAN_H=no
fi
fi
if test "$USE_SYS_ENDIAN_H" = "yes" ; then
AC_DEFINE([USE_SYS_ENDIAN_H], 1,
[Define to use byteswap macros from <sys/endian.h>])
AC_DEFINE_UNQUOTED([bswap_16], ${BSWAP}16,
[Define to 16-bit byteswap macro])
AC_DEFINE_UNQUOTED([bswap_32], ${BSWAP}32,
[Define to 32-bit byteswap macro])
AC_DEFINE_UNQUOTED([bswap_64], ${BSWAP}64,
[Define to 64-bit byteswap macro])
fi
fi
dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([geteuid getuid link memmove memset mkstemp strchr strrchr \

View File

@ -93,6 +93,9 @@
/* Define to 1 if you have the <asm/mtrr.h> header file. */
#undef HAVE_ASM_MTRR_H
/* Define to 1 if you have the <byteswap.h> header file. */
#undef HAVE_BYTESWAP_H
/* Define to 1 if you have the <dbm.h> header file. */
#undef HAVE_DBM_H
@ -311,6 +314,9 @@
/* Use rgb.txt directly */
#undef USE_RGB_TXT
/* Define to use byteswap macros from <sys/endian.h> */
#undef USE_SYS_ENDIAN_H
/* unaligned word accesses behave as expected */
#undef WORKING_UNALIGNED_INT
@ -469,4 +475,13 @@
/* Path to XErrorDB file */
#undef XERRORDB_PATH
/* Define to 16-bit byteswap macro */
#undef bswap_16
/* Define to 32-bit byteswap macro */
#undef bswap_32
/* Define to 64-bit byteswap macro */
#undef bswap_64
#endif /* _DIX_CONFIG_H_ */