Home | History | Annotate | Line # | Download | only in include
bswap.h revision 1.3
      1 /*      $NetBSD: bswap.h,v 1.3 2002/03/17 17:55:24 uch 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(u_int16_t);
     14 u_int32_t bswap32(u_int32_t);
     15 u_int64_t bswap64(u_int64_t);
     16 __END_DECLS
     17 
     18 #else /* _KERNEL */
     19 
     20 __BEGIN_DECLS
     21 static __inline u_int16_t bswap16(u_int16_t);
     22 static __inline u_int32_t bswap32(u_int32_t);
     23 u_int64_t bswap64(u_int64_t);
     24 __END_DECLS
     25 
     26 static __inline u_int16_t
     27 bswap16(u_int16_t x)
     28 {
     29 	u_int16_t rval;
     30 
     31 	__asm __volatile ("swap.b %1,%0" : "=r"(rval) : "r"(x));
     32 
     33 	return (rval);
     34 }
     35 
     36 static __inline u_int32_t
     37 bswap32(u_int32_t x)
     38 {
     39 	u_int32_t rval;
     40 
     41 	__asm __volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0"
     42 			  : "=r"(rval) : "r"(x));
     43 
     44 	return (rval);
     45 }
     46 #endif /* _KERNEL */
     47 
     48 #endif /* !_SH3_BSWAP_H_ */
     49