xref: /openbsd/sys/arch/sh/include/endian.h (revision 5af055cd)
1 /*	$OpenBSD: endian.h,v 1.5 2014/07/12 16:25:09 guenther Exp $	*/
2 /*	$NetBSD: endian.h,v 1.4 2000/03/17 00:09:25 mycroft Exp $	*/
3 
4 /* Written by Manuel Bouyer. Public domain */
5 
6 #ifndef _SH_ENDIAN_H_
7 #define	_SH_ENDIAN_H_
8 
9 #ifdef  __GNUC__
10 
11 #define	__swap64md	__swap64gen
12 
13 #define __swap16md(x) __statement({					\
14 	uint16_t rval;							\
15 									\
16 	__asm volatile ("swap.b %1,%0" : "=r"(rval) : "r"(x));		\
17 									\
18 	rval;								\
19 })
20 
21 #define __swap32md(x) __statement({					\
22 	uint32_t rval;							\
23 									\
24 	__asm volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0"	\
25 			  : "=r"(rval) : "r"(x));			\
26 									\
27 	rval;								\
28 })
29 
30 #define __HAVE_MD_SWAP
31 
32 #endif /* __GNUC_ */
33 
34 #ifdef __LITTLE_ENDIAN__
35 #define	_BYTE_ORDER _LITTLE_ENDIAN
36 #else
37 #define	_BYTE_ORDER _BIG_ENDIAN
38 #endif
39 #define	__STRICT_ALIGNMENT
40 
41 #ifndef __FROM_SYS__ENDIAN
42 #include <sys/endian.h>
43 #endif
44 
45 #endif /* !_SH_ENDIAN_H_ */
46