1706f2543Smrg/*
2706f2543Smrg * (C) Copyright IBM Corporation 2006, 2007
3706f2543Smrg * All Rights Reserved.
4706f2543Smrg *
5706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6706f2543Smrg * copy of this software and associated documentation files (the "Software"),
7706f2543Smrg * to deal in the Software without restriction, including without limitation
8706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sub license,
9706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the
10706f2543Smrg * Software is furnished to do so, subject to the following conditions:
11706f2543Smrg *
12706f2543Smrg * The above copyright notice and this permission notice (including the next
13706f2543Smrg * paragraph) shall be included in all copies or substantial portions of the
14706f2543Smrg * Software.
15706f2543Smrg *
16706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19706f2543Smrg * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
20706f2543Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21706f2543Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22706f2543Smrg * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23706f2543Smrg */
24706f2543Smrg
25706f2543Smrg/**
26706f2543Smrg * \file glxbyteorder.h
27706f2543Smrg * Platform glue for handling byte-ordering issues in GLX protocol.
28706f2543Smrg *
29706f2543Smrg * \author Ian Romanick <idr@us.ibm.com>
30706f2543Smrg */
31706f2543Smrg#if !defined(__GLXBYTEORDER_H__)
32706f2543Smrg#define __GLXBYTEORDER_H__
33706f2543Smrg
34706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
35706f2543Smrg#include <dix-config.h>
36706f2543Smrg#endif
37706f2543Smrg
38706f2543Smrg#if HAVE_BYTESWAP_H
39706f2543Smrg#include <byteswap.h>
40706f2543Smrg#elif defined(USE_SYS_ENDIAN_H)
41706f2543Smrg#include <sys/endian.h>
42706f2543Smrg#elif defined(__APPLE__)
43706f2543Smrg#include <libkern/OSByteOrder.h>
44706f2543Smrg#define bswap_16 OSSwapInt16
45706f2543Smrg#define bswap_32 OSSwapInt32
46706f2543Smrg#define bswap_64 OSSwapInt64
47706f2543Smrg#else
48706f2543Smrg#define	bswap_16(value)  \
49706f2543Smrg 	((((value) & 0xff) << 8) | ((value) >> 8))
50706f2543Smrg
51706f2543Smrg#define	bswap_32(value)	\
52706f2543Smrg 	(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
53706f2543Smrg 	(uint32_t)bswap_16((uint16_t)((value) >> 16)))
54706f2543Smrg
55706f2543Smrg#define	bswap_64(value)	\
56706f2543Smrg 	(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
57706f2543Smrg 	    << 32) | \
58706f2543Smrg 	(uint64_t)bswap_32((uint32_t)((value) >> 32)))
59706f2543Smrg#endif
60706f2543Smrg
61706f2543Smrg#endif /* !defined(__GLXBYTEORDER_H__) */
62