11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*	$OpenBSD: endian.h,v 1.17 2006/01/06 18:53:05 millert Exp $	*/
21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*-
41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (c) 1997 Niklas Hallqvist.  All rights reserved.
51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *
61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Redistribution and use in source and binary forms, with or without
71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * modification, are permitted provided that the following conditions
81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * are met:
91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 1. Redistributions of source code must retain the above copyright
101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    notice, this list of conditions and the following disclaimer.
111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright
121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    notice, this list of conditions and the following disclaimer in the
131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    documentation and/or other materials provided with the distribution.
141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *
151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */
261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Generic definitions for little- and big-endian systems.  Other endianesses
291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * has to be dealt with in the specific machine/endian.h file for that port.
301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *
311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * This file is meant to be included from a little- or big-endian port's
321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * machine/endian.h after setting _BYTE_ORDER to either 1234 for little endian
331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * or 4321 for big..
341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */
351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _SYS_ENDIAN_H_
371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _SYS_ENDIAN_H_
381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <sys/cdefs.h>
401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <machine/_types.h>
411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _LITTLE_ENDIAN	1234
431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _BIG_ENDIAN	4321
441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _PDP_ENDIAN	3412
451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if __BSD_VISIBLE
471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define LITTLE_ENDIAN	_LITTLE_ENDIAN
481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define BIG_ENDIAN	_BIG_ENDIAN
491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define PDP_ENDIAN	_PDP_ENDIAN
501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define BYTE_ORDER	_BYTE_ORDER
511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef __GNUC__
541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap16gen(x) __statement({					\
561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__uint16_t __swap16gen_x = (x);					\
571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project									\
581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	(__uint16_t)((__swap16gen_x & 0xff) << 8 |			\
591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap16gen_x & 0xff00) >> 8);				\
601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project})
611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap32gen(x) __statement({					\
631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__uint32_t __swap32gen_x = (x);					\
641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project									\
651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	(__uint32_t)((__swap32gen_x & 0xff) << 24 |			\
661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap32gen_x & 0xff00) << 8 |				\
671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap32gen_x & 0xff0000) >> 8 |				\
681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap32gen_x & 0xff000000) >> 24);			\
691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project})
701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap64gen(x) __statement({					\
721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__uint64_t __swap64gen_x = (x);					\
731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project									\
741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	(__uint64_t)((__swap64gen_x & 0xff) << 56 |			\
751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap64gen_x & 0xff00ULL) << 40 |				\
761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap64gen_x & 0xff0000ULL) << 24 |			\
771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap64gen_x & 0xff000000ULL) << 8 |			\
781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap64gen_x & 0xff00000000ULL) >> 8 |			\
791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap64gen_x & 0xff0000000000ULL) >> 24 |			\
801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap64gen_x & 0xff000000000000ULL) >> 40 |		\
811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    (__swap64gen_x & 0xff00000000000000ULL) >> 56);		\
821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project})
831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else /* __GNUC__ */
851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Note that these macros evaluate their arguments several times.  */
871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap16gen(x)							\
881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    (__uint16_t)(((__uint16_t)(x) & 0xff) << 8 | ((__uint16_t)(x) & 0xff00) >> 8)
891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap32gen(x)							\
911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    (__uint32_t)(((__uint32_t)(x) & 0xff) << 24 |			\
921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    ((__uint32_t)(x) & 0xff00) << 8 | ((__uint32_t)(x) & 0xff0000) >> 8 |\
931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project    ((__uint32_t)(x) & 0xff000000) >> 24)
941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap64gen(x)							\
961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	(__uint64_t)((((__uint64_t)(x) & 0xff) << 56) |			\
971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    ((__uint64_t)(x) & 0xff00ULL) << 40 |			\
981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    ((__uint64_t)(x) & 0xff0000ULL) << 24 |			\
991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    ((__uint64_t)(x) & 0xff000000ULL) << 8 |			\
1001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    ((__uint64_t)(x) & 0xff00000000ULL) >> 8 |			\
1011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    ((__uint64_t)(x) & 0xff0000000000ULL) >> 24 |		\
1021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    ((__uint64_t)(x) & 0xff000000000000ULL) >> 40 |		\
1031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    ((__uint64_t)(x) & 0xff00000000000000ULL) >> 56)
1041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1051dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* __GNUC__ */
1061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
1081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Define MD_SWAP if you provide swap{16,32}md functions/macros that are
1091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * optimized for your architecture,  These will be used for swap{16,32}
1101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * unless the argument is a constant and we are using GCC, where we can
1111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * take advantage of the CSE phase much better by using the generic version.
1121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */
1131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef MD_SWAP
1141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if __GNUC__
1151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap16(x) __statement({					\
1171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__uint16_t __swap16_x = (x);					\
1181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project									\
1191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__builtin_constant_p(x) ? __swap16gen(__swap16_x) :		\
1201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    __swap16md(__swap16_x);					\
1211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project})
1221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap32(x) __statement({					\
1241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__uint32_t __swap32_x = (x);					\
1251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project									\
1261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__builtin_constant_p(x) ? __swap32gen(__swap32_x) :		\
1271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    __swap32md(__swap32_x);					\
1281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project})
1291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap64(x) __statement({					\
1311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__uint64_t __swap64_x = (x);					\
1321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project									\
1331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__builtin_constant_p(x) ? __swap64gen(__swap64_x) :		\
1341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	    __swap64md(__swap64_x);					\
1351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project})
1361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* __GNUC__  */
1381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else /* MD_SWAP */
1401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap16 __swap16gen
1411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap32 __swap32gen
1421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap64 __swap64gen
1431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* MD_SWAP */
1441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __swap16_multi(v, n) do {						\
1461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__size_t __swap16_multi_n = (n);				\
1471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	__uint16_t *__swap16_multi_v = (v);				\
1481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project									\
1491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	while (__swap16_multi_n) {					\
1501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project		*__swap16_multi_v = swap16(*__swap16_multi_v);		\
1511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project		__swap16_multi_v++;					\
1521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project		__swap16_multi_n--;					\
1531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project	}								\
1541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} while (0)
1551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if __BSD_VISIBLE
1571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define swap16 __swap16
1581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define swap32 __swap32
1591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define swap64 __swap64
1601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define swap16_multi __swap16_multi
1611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__BEGIN_DECLS
1631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint64_t	htobe64(__uint64_t);
1641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint32_t	htobe32(__uint32_t);
1651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint16_t	htobe16(__uint16_t);
1661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint64_t	betoh64(__uint64_t);
1671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint32_t	betoh32(__uint32_t);
1681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint16_t	betoh16(__uint16_t);
1691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint64_t	htole64(__uint64_t);
1711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint32_t	htole32(__uint32_t);
1721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint16_t	htole16(__uint16_t);
1731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint64_t	letoh64(__uint64_t);
1741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint32_t	letoh32(__uint32_t);
1751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__uint16_t	letoh16(__uint16_t);
1761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__END_DECLS
1771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* __BSD_VISIBLE */
1781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if _BYTE_ORDER == _LITTLE_ENDIAN
1801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Can be overridden by machine/endian.h before inclusion of this file.  */
1821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _QUAD_HIGHWORD
1831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _QUAD_HIGHWORD 1
1841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
1851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _QUAD_LOWWORD
1861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _QUAD_LOWWORD 0
1871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
1881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if __BSD_VISIBLE
1901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htobe16 __swap16
1911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htobe32 __swap32
1921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htobe64 __swap64
1931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define betoh16 __swap16
1941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define betoh32 __swap32
1951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define betoh64 __swap64
1961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htole16(x) (x)
1981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htole32(x) (x)
1991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htole64(x) (x)
2001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define letoh16(x) (x)
2011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define letoh32(x) (x)
2021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define letoh64(x) (x)
2031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* __BSD_VISIBLE */
2041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2051dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htons(x) __swap16(x)
2061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htonl(x) __swap32(x)
2071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define ntohs(x) __swap16(x)
2081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define ntohl(x) __swap32(x)
2091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Bionic additions */
2111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define ntohq(x) __swap64(x)
2121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htonq(x) __swap64(x)
2131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __LITTLE_ENDIAN_BITFIELD
2151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* _BYTE_ORDER */
2171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if _BYTE_ORDER == _BIG_ENDIAN
2191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Can be overridden by machine/endian.h before inclusion of this file.  */
2211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _QUAD_HIGHWORD
2221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _QUAD_HIGHWORD 0
2231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
2241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _QUAD_LOWWORD
2251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _QUAD_LOWWORD 1
2261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
2271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if __BSD_VISIBLE
2291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htole16 __swap16
2301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htole32 __swap32
2311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htole64 __swap64
2321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define letoh16 __swap16
2331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define letoh32 __swap32
2341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define letoh64 __swap64
2351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htobe16(x) (x)
2371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htobe32(x) (x)
2381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htobe64(x) (x)
2391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define betoh16(x) (x)
2401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define betoh32(x) (x)
2411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define betoh64(x) (x)
2421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* __BSD_VISIBLE */
2431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htons(x) (x)
2451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htonl(x) (x)
2461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define ntohs(x) (x)
2471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define ntohl(x) (x)
2481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Bionic additions */
2501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define ntohq(x) (x)
2511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define htonq(x) (x)
2521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __BIG_ENDIAN_BITFIELD
2541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* _BYTE_ORDER */
2561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if __BSD_VISIBLE
2581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define	NTOHL(x) (x) = ntohl((u_int32_t)(x))
2591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define	NTOHS(x) (x) = ntohs((u_int16_t)(x))
2601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define	HTONL(x) (x) = htonl((u_int32_t)(x))
2611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define	HTONS(x) (x) = htons((u_int16_t)(x))
2621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
2631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define  __BYTE_ORDER       _BYTE_ORDER
2661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef  __LITTLE_ENDIAN
2671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define  __LITTLE_ENDIAN    _LITTLE_ENDIAN
2681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
2691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef  __BIG_ENDIAN
2701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define  __BIG_ENDIAN       _BIG_ENDIAN
2711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
2721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* _SYS_ENDIAN_H_ */
274