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