b9a21c3c91c47e090316e28d759194e46628ed49vboxsync/*
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * (C) Copyright IBM Corporation 2006, 2007
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * All Rights Reserved.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync *
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * Permission is hereby granted, free of charge, to any person obtaining a
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * copy of this software and associated documentation files (the "Software"),
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * to deal in the Software without restriction, including without limitation
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * the rights to use, copy, modify, merge, publish, distribute, sub license,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * and/or sell copies of the Software, and to permit persons to whom the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * Software is furnished to do so, subject to the following conditions:
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync *
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * The above copyright notice and this permission notice (including the next
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * paragraph) shall be included in all copies or substantial portions of the
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * Software.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync *
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync/**
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * \file glxbyteorder.h
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * Platform glue for handling byte-ordering issues in GLX protocol.
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync *
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync * \author Ian Romanick <idr@us.ibm.com>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync */
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#if !defined(__GLXBYTEORDER_H__)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#define __GLXBYTEORDER_H__
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#ifdef HAVE_DIX_CONFIG_H
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#include <dix-config.h>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#endif
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#if HAVE_BYTESWAP_H
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#include <byteswap.h>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#elif defined(USE_SYS_ENDIAN_H)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#include <sys/endian.h>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#elif defined(__APPLE__)
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#include <libkern/OSByteOrder.h>
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#define bswap_16 OSSwapInt16
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#define bswap_32 OSSwapInt32
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#define bswap_64 OSSwapInt64
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#else
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#define bswap_16(value) \
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync ((((value) & 0xff) << 8) | ((value) >> 8))
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#define bswap_32(value) \
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (uint32_t)bswap_16((uint16_t)((value) >> 16)))
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#define bswap_64(value) \
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync << 32) | \
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync (uint64_t)bswap_32((uint32_t)((value) >> 32)))
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#endif
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync
b9a21c3c91c47e090316e28d759194e46628ed49vboxsync#endif /* !defined(__GLXBYTEORDER_H__) */