1 /* $OpenBSD: endian.h,v 1.11 2018/10/02 21:30:44 naddy Exp $ */ 2 3 /* 4 * Copyright (c) 2015 David Gwynne <dlg@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _ARM_ENDIAN_H_ 20 #define _ARM_ENDIAN_H_ 21 22 #ifndef __FROM_SYS__ENDIAN 23 #include <sys/_types.h> 24 #endif 25 26 static __inline __uint16_t 27 __swap16md(__uint16_t _x) 28 { 29 __uint16_t _rv; 30 31 __asm ("rev16 %0, %1" : "=r" (_rv) : "r" (_x)); 32 33 return (_rv); 34 } 35 36 static __inline __uint32_t 37 __swap32md(__uint32_t _x) 38 { 39 __uint32_t _rv; 40 41 __asm ("rev %0, %1" : "=r" (_rv) : "r" (_x)); 42 43 return (_rv); 44 } 45 46 static __inline __uint64_t 47 __swap64md(__uint64_t _x) 48 { 49 __uint64_t _rv; 50 51 _rv = (__uint64_t)__swap32md(_x >> 32) | 52 (__uint64_t)__swap32md(_x) << 32; 53 54 return (_rv); 55 } 56 57 /* Tell sys/endian.h we have MD variants of the swap macros. */ 58 #define __HAVE_MD_SWAP 59 60 #define _BYTE_ORDER _LITTLE_ENDIAN 61 #define __STRICT_ALIGNMENT 62 63 #ifndef __FROM_SYS__ENDIAN 64 #include <sys/endian.h> 65 #endif 66 #endif /* _ARM_ENDIAN_H_ */ 67