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