1*8e38c3aaSriastradh /* $NetBSD: byteorder.h,v 1.2 2021/12/19 10:56:30 riastradh Exp $ */ 236e6f0b2Sriastradh 336e6f0b2Sriastradh /*- 436e6f0b2Sriastradh * Copyright (c) 2013 The NetBSD Foundation, Inc. 536e6f0b2Sriastradh * All rights reserved. 636e6f0b2Sriastradh * 736e6f0b2Sriastradh * This code is derived from software contributed to The NetBSD Foundation 836e6f0b2Sriastradh * by Taylor R. Campbell. 936e6f0b2Sriastradh * 1036e6f0b2Sriastradh * Redistribution and use in source and binary forms, with or without 1136e6f0b2Sriastradh * modification, are permitted provided that the following conditions 1236e6f0b2Sriastradh * are met: 1336e6f0b2Sriastradh * 1. Redistributions of source code must retain the above copyright 1436e6f0b2Sriastradh * notice, this list of conditions and the following disclaimer. 1536e6f0b2Sriastradh * 2. Redistributions in binary form must reproduce the above copyright 1636e6f0b2Sriastradh * notice, this list of conditions and the following disclaimer in the 1736e6f0b2Sriastradh * documentation and/or other materials provided with the distribution. 1836e6f0b2Sriastradh * 1936e6f0b2Sriastradh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2036e6f0b2Sriastradh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2136e6f0b2Sriastradh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2236e6f0b2Sriastradh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2336e6f0b2Sriastradh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2436e6f0b2Sriastradh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2536e6f0b2Sriastradh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2636e6f0b2Sriastradh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2736e6f0b2Sriastradh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2836e6f0b2Sriastradh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2936e6f0b2Sriastradh * POSSIBILITY OF SUCH DAMAGE. 3036e6f0b2Sriastradh */ 3136e6f0b2Sriastradh 3236e6f0b2Sriastradh #ifndef _ASM_BYTEORDER_H_ 3336e6f0b2Sriastradh #define _ASM_BYTEORDER_H_ 3436e6f0b2Sriastradh 3536e6f0b2Sriastradh #include <sys/endian.h> 3636e6f0b2Sriastradh 37*8e38c3aaSriastradh #if _BYTE_ORDER == _LITTLE_ENDIAN 38*8e38c3aaSriastradh #define __LITTLE_ENDIAN 39*8e38c3aaSriastradh #elif _BYTE_ORDER == _BIG_ENDIAN 40*8e38c3aaSriastradh #define __BIG_ENDIAN 41*8e38c3aaSriastradh #else 42*8e38c3aaSriastradh #error Unknown byte order! 43*8e38c3aaSriastradh #endif 44*8e38c3aaSriastradh 4536e6f0b2Sriastradh #define cpu_to_le16 htole16 4636e6f0b2Sriastradh #define cpu_to_le32 htole32 4736e6f0b2Sriastradh #define cpu_to_le64 htole64 4836e6f0b2Sriastradh #define cpu_to_be16 htobe16 4936e6f0b2Sriastradh #define cpu_to_be32 htobe32 5036e6f0b2Sriastradh #define cpu_to_be64 htobe64 5136e6f0b2Sriastradh 5236e6f0b2Sriastradh #define le16_to_cpu le16toh 5336e6f0b2Sriastradh #define le32_to_cpu le32toh 5436e6f0b2Sriastradh #define le64_to_cpu le64toh 5536e6f0b2Sriastradh #define be16_to_cpu be16toh 5636e6f0b2Sriastradh #define be32_to_cpu be32toh 5736e6f0b2Sriastradh #define be64_to_cpu be64toh 5836e6f0b2Sriastradh 5936e6f0b2Sriastradh #define be16_to_cpup be16dec 6036e6f0b2Sriastradh #define be32_to_cpup be32dec 6136e6f0b2Sriastradh #define be64_to_cpup be64dec 6236e6f0b2Sriastradh #define le16_to_cpup le16dec 6336e6f0b2Sriastradh #define le32_to_cpup le32dec 6436e6f0b2Sriastradh #define le64_to_cpup le64dec 6536e6f0b2Sriastradh 6636e6f0b2Sriastradh #endif /* _ASM_BYTEORDER_H_ */ 67