xref: /netbsd-src/sys/arch/sh3/include/byte_swap.h (revision 221fe583b623b3187fc76ac9cd92631ed4eaa711)
1*221fe583Sskrll /*      $NetBSD: byte_swap.h,v 1.4 2006/02/17 08:23:26 skrll Exp $      */
228cb02c9Sdsl 
328cb02c9Sdsl /* Written by Manuel Bouyer. Public domain */
428cb02c9Sdsl 
5c36e4cf5Sskrll #ifndef _SH3_BYTE_SWAP_H_
6c36e4cf5Sskrll #define	_SH3_BYTE_SWAP_H_
728cb02c9Sdsl 
828cb02c9Sdsl #include <sys/cdefs.h>
928cb02c9Sdsl 
1028cb02c9Sdsl #ifdef  __GNUC__
1128cb02c9Sdsl #include <sys/types.h>
1228cb02c9Sdsl __BEGIN_DECLS
1328cb02c9Sdsl 
1428cb02c9Sdsl #define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
15fbae48b9Sperry static __inline uint16_t
__byte_swap_u16_variable(uint16_t x)1628cb02c9Sdsl __byte_swap_u16_variable(uint16_t x)
1728cb02c9Sdsl {
1828cb02c9Sdsl 	uint16_t rval;
1928cb02c9Sdsl 
2028cb02c9Sdsl 	__asm volatile ("swap.b %1,%0" : "=r"(rval) : "r"(x));
2128cb02c9Sdsl 
2228cb02c9Sdsl 	return (rval);
2328cb02c9Sdsl }
2428cb02c9Sdsl 
2528cb02c9Sdsl #define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
26fbae48b9Sperry static __inline uint32_t
__byte_swap_u32_variable(uint32_t x)2728cb02c9Sdsl __byte_swap_u32_variable(uint32_t x)
2828cb02c9Sdsl {
2928cb02c9Sdsl 	uint32_t rval;
3028cb02c9Sdsl 
3128cb02c9Sdsl 	__asm volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0"
3228cb02c9Sdsl 			  : "=r"(rval) : "r"(x));
3328cb02c9Sdsl 
3428cb02c9Sdsl 	return (rval);
3528cb02c9Sdsl }
3628cb02c9Sdsl 
3728cb02c9Sdsl __END_DECLS
38*221fe583Sskrll #endif /* __GNUC_ */
3928cb02c9Sdsl 
40c36e4cf5Sskrll #endif /* !_SH3_BYPE_SWAP_H_ */
41