Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: byte_swap.h,v 1.8 2009/04/30 07:01:27 skrll Exp $	*/
      2 
      3 /*	$OpenBSD: endian.h,v 1.8 2004/04/07 18:24:19 mickey Exp $	*/
      4 
      5 /*
      6  * Copyright (c) 1998-2004 Michael Shalayeff
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     28  * THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef _HPPA_BYTE_SWAP_H_
     32 #define	_HPPA_BYTE_SWAP_H_
     33 
     34 #ifdef __GNUC__
     35 #include <sys/types.h>
     36 __BEGIN_DECLS
     37 
     38 
     39 #define	__BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
     40 static __inline uint32_t __byte_swap_u32_variable(uint32_t);
     41 static __inline uint32_t
     42 __byte_swap_u32_variable(uint32_t x)
     43 {
     44 	register uint32_t __swap32md_x;	\
     45 						\
     46 	__asm  ("extru	%1, 7,8,%%r22\n\t"	\
     47 		"shd	%1,%1,8,%0\n\t"		\
     48 		"dep	%0,15,8,%0\n\t"		\
     49 		"dep	%%r22,31,8,%0"		\
     50 		: "=&r" (__swap32md_x)		\
     51 		: "r" (x) : "r22");		\
     52 	return(__swap32md_x);
     53 }
     54 
     55 #if 0
     56 /*
     57  * Use generic C version because w/ asm __inline below
     58  * gcc inserts extra "extru r,31,16,r" to convert
     59  * to 16 bit entity, which produces overhead we don't need.
     60  * Besides, gcc does swap16 same way by itself.
     61  */
     62 #define	__swap16md(x)	__swap16gen(x)
     63 #else
     64 #define	__BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
     65 static __inline uint16_t __byte_swap_u16_variable(uint16_t);
     66 static __inline uint16_t
     67 __byte_swap_u16_variable(uint16_t x)
     68 {
     69 	register uint16_t __swap16md_x;				\
     70 									\
     71 	__asm  ("extru	%1,23,8,%0\n\t"					\
     72 		"dep	%1,23,8,%0"					\
     73 	       : "=&r" (__swap16md_x) : "r" (x));			\
     74 	return(__swap16md_x);
     75 }
     76 #endif
     77 
     78 __END_DECLS
     79 #endif
     80 
     81 #endif /* !_HPPA_BYTE_SWAP_H_ */
     82