xref: /netbsd-src/sys/arch/vax/include/byte_swap.h (revision 1990f7e47c7797fb81b2303227e2e0a5a170255c)
1*1990f7e4Schristos /*	$NetBSD: byte_swap.h,v 1.12 2017/01/14 16:21:28 christos Exp $	*/
2dc306354Sbouyer 
3dc306354Sbouyer /*
4dc306354Sbouyer  * Copyright (c) 1987, 1991 Regents of the University of California.
5dc306354Sbouyer  * All rights reserved.
6dc306354Sbouyer  *
7dc306354Sbouyer  * Redistribution and use in source and binary forms, with or without
8dc306354Sbouyer  * modification, are permitted provided that the following conditions
9dc306354Sbouyer  * are met:
10dc306354Sbouyer  * 1. Redistributions of source code must retain the above copyright
11dc306354Sbouyer  *    notice, this list of conditions and the following disclaimer.
12dc306354Sbouyer  * 2. Redistributions in binary form must reproduce the above copyright
13dc306354Sbouyer  *    notice, this list of conditions and the following disclaimer in the
14dc306354Sbouyer  *    documentation and/or other materials provided with the distribution.
15aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
16dc306354Sbouyer  *    may be used to endorse or promote products derived from this software
17dc306354Sbouyer  *    without specific prior written permission.
18dc306354Sbouyer  *
19dc306354Sbouyer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20dc306354Sbouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21dc306354Sbouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22dc306354Sbouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23dc306354Sbouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24dc306354Sbouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25dc306354Sbouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26dc306354Sbouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27dc306354Sbouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28dc306354Sbouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29dc306354Sbouyer  * SUCH DAMAGE.
30dc306354Sbouyer  *
31dc306354Sbouyer  *      @(#)endian.h    7.8 (Berkeley) 4/3/91
32dc306354Sbouyer  */
33dc306354Sbouyer 
34dc306354Sbouyer #ifndef _VAX_BYTE_SWAP_H_
35dc306354Sbouyer #define _VAX_BYTE_SWAP_H_
3621650978Sskrll 
37c88ae1f9Sdsl #ifdef __GNUC__
38c88ae1f9Sdsl #include <sys/types.h>
39c88ae1f9Sdsl __BEGIN_DECLS
40dc306354Sbouyer 
41c88ae1f9Sdsl #define	__BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
42e7b322a5Sperry static __inline uint32_t __attribute__((__unused__))
__byte_swap_u32_variable(uint32_t x)43c88ae1f9Sdsl __byte_swap_u32_variable(uint32_t x)
442494c460Sthorpej {
452494c460Sthorpej 	uint32_t y;
46dc306354Sbouyer 
475f1c88d7Sperry 	__asm volatile(
482494c460Sthorpej 		"rotl	$-8, %1, %0	\n"
492494c460Sthorpej 		"insv	%0, $16, $8, %0	\n"
5028b1aa2bSmatt 		"rotl	$8, %1, %%r1	\n"
5128b1aa2bSmatt 		"movb	%%r1, %0"
522494c460Sthorpej 		: "=&r" (y)
532494c460Sthorpej 		: "r" (x)
542494c460Sthorpej 		: "r1", "cc");
552494c460Sthorpej 
562494c460Sthorpej 	return (y);
572494c460Sthorpej }
582494c460Sthorpej 
59c88ae1f9Sdsl #define	__BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
60e7b322a5Sperry static __inline uint16_t __attribute__((__unused__))
__byte_swap_u16_variable(uint16_t x)61c88ae1f9Sdsl __byte_swap_u16_variable(uint16_t x)
622494c460Sthorpej {
632494c460Sthorpej 
64*1990f7e4Schristos 	return (uint16_t)(x << 8 | x >> 8);
652494c460Sthorpej }
66dc306354Sbouyer 
67c88ae1f9Sdsl __END_DECLS
68c88ae1f9Sdsl #endif
69dc306354Sbouyer #endif /* _VAX_BYTE_SWAP_H_ */
70