Home | History | Annotate | Line # | Download | only in include
byte_swap.h revision 1.6
      1 /*	$NetBSD: byte_swap.h,v 1.6 2006/01/30 22:46:35 dsl Exp $	*/
      2 
      3 /*	$OpenBSD: endian.h,v 1.7 2001/06/29 20:28:54 mickey Exp $	*/
      4 
      5 /*
      6  * Copyright (c) 1998-2001 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  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by Michael Shalayeff.
     20  * 4. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #ifndef _HPPA_BYTE_SWAP_H_
     36 #define	_HPPA_BYTE_SWAP_H_
     37 
     38 #ifdef __GNUC__
     39 #include <sys/types.h>
     40 __BEGIN_DECLS
     41 
     42 
     43 #define	__BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
     44 static __inline uint32_t __byte_swap_u32_variable(uint32_t);
     45 static __inline uint32_t
     46 __byte_swap_u32_variable(uint32_t x)
     47 {
     48 	register in_addr_t __swap32md_x;	\
     49 						\
     50 	__asm  ("extru	%1, 7,8,%%r22\n\t"	\
     51 		"shd	%1,%1,8,%0\n\t"		\
     52 		"dep	%0,15,8,%0\n\t"		\
     53 		"dep	%%r22,31,8,%0"		\
     54 		: "=&r" (__swap32md_x)		\
     55 		: "r" (x) : "r22");		\
     56 	return(__swap32md_x);
     57 }
     58 
     59 #if 0
     60 /*
     61  * Use generic C version because w/ asm __inline below
     62  * gcc inserts extra "extru r,31,16,r" to convert
     63  * to 16 bit entity, which produces overhead we don't need.
     64  * Besides, gcc does swap16 same way by itself.
     65  */
     66 #define	__swap16md(x)	__swap16gen(x)
     67 #else
     68 #define	__BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
     69 static __inline uint16_t __byte_swap_u16_variable(uint16_t);
     70 static __inline uint16_t
     71 __byte_swap_u16_variable(uint16_t x)
     72 {
     73 	register in_port_t __swap16md_x;				\
     74 									\
     75 	__asm  ("extru	%1,23,8,%0\n\t"					\
     76 		"dep	%1,23,8,%0"					\
     77 	       : "=&r" (__swap16md_x) : "r" (x));			\
     78 	return(__swap16md_x);
     79 }
     80 #endif
     81 
     82 __END_DECLS
     83 #endif
     84 
     85 #endif /* !_HPPA_BYTE_SWAP_H_ */
     86