Home | History | Annotate | Line # | Download | only in include
      1 /*      $NetBSD: byte_swap.h,v 1.4 2006/02/17 08:23:26 skrll Exp $      */
      2 
      3 /* Written by Manuel Bouyer. Public domain */
      4 
      5 #ifndef _SH3_BYTE_SWAP_H_
      6 #define	_SH3_BYTE_SWAP_H_
      7 
      8 #include <sys/cdefs.h>
      9 
     10 #ifdef  __GNUC__
     11 #include <sys/types.h>
     12 __BEGIN_DECLS
     13 
     14 #define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
     15 static __inline uint16_t
     16 __byte_swap_u16_variable(uint16_t x)
     17 {
     18 	uint16_t rval;
     19 
     20 	__asm volatile ("swap.b %1,%0" : "=r"(rval) : "r"(x));
     21 
     22 	return (rval);
     23 }
     24 
     25 #define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
     26 static __inline uint32_t
     27 __byte_swap_u32_variable(uint32_t x)
     28 {
     29 	uint32_t rval;
     30 
     31 	__asm volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0"
     32 			  : "=r"(rval) : "r"(x));
     33 
     34 	return (rval);
     35 }
     36 
     37 __END_DECLS
     38 #endif /* __GNUC_ */
     39 
     40 #endif /* !_SH3_BYPE_SWAP_H_ */
     41