Home | History | Annotate | Line # | Download | only in include
bswap.h revision 1.4
      1  1.4     uch /*      $NetBSD: bswap.h,v 1.4 2002/04/28 17:10:33 uch Exp $      */
      2  1.1  itojun 
      3  1.1  itojun /* Written by Manuel Bouyer. Public domain */
      4  1.1  itojun 
      5  1.1  itojun #ifndef _SH3_BSWAP_H_
      6  1.4     uch #define	_SH3_BSWAP_H_
      7  1.1  itojun 
      8  1.1  itojun #include <sys/cdefs.h>
      9  1.1  itojun 
     10  1.1  itojun #ifndef _KERNEL
     11  1.1  itojun 
     12  1.1  itojun __BEGIN_DECLS
     13  1.2     uch u_int16_t bswap16(u_int16_t);
     14  1.2     uch u_int32_t bswap32(u_int32_t);
     15  1.2     uch u_int64_t bswap64(u_int64_t);
     16  1.1  itojun __END_DECLS
     17  1.1  itojun 
     18  1.1  itojun #else /* _KERNEL */
     19  1.1  itojun 
     20  1.1  itojun __BEGIN_DECLS
     21  1.2     uch static __inline u_int16_t bswap16(u_int16_t);
     22  1.2     uch static __inline u_int32_t bswap32(u_int32_t);
     23  1.2     uch u_int64_t bswap64(u_int64_t);
     24  1.1  itojun __END_DECLS
     25  1.1  itojun 
     26  1.1  itojun static __inline u_int16_t
     27  1.2     uch bswap16(u_int16_t x)
     28  1.1  itojun {
     29  1.1  itojun 	u_int16_t rval;
     30  1.1  itojun 
     31  1.1  itojun 	__asm __volatile ("swap.b %1,%0" : "=r"(rval) : "r"(x));
     32  1.1  itojun 
     33  1.2     uch 	return (rval);
     34  1.1  itojun }
     35  1.1  itojun 
     36  1.1  itojun static __inline u_int32_t
     37  1.2     uch bswap32(u_int32_t x)
     38  1.1  itojun {
     39  1.1  itojun 	u_int32_t rval;
     40  1.1  itojun 
     41  1.1  itojun 	__asm __volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0"
     42  1.1  itojun 			  : "=r"(rval) : "r"(x));
     43  1.1  itojun 
     44  1.2     uch 	return (rval);
     45  1.1  itojun }
     46  1.1  itojun #endif /* _KERNEL */
     47  1.1  itojun 
     48  1.3     uch #endif /* !_SH3_BSWAP_H_ */
     49