xref: /dragonfly/contrib/lvm2/dist/include/xlate.h (revision 6ca88057)
1 /*	$NetBSD: xlate.h,v 1.1.1.1 2008/12/22 00:18:44 haad Exp $	*/
2 
3 /*
4  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5  * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
6  *
7  * This file is part of LVM2.
8  *
9  * This copyrighted material is made available to anyone wishing to use,
10  * modify, copy, or redistribute it subject to the terms and conditions
11  * of the GNU Lesser General Public License v.2.1.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17 
18 #ifndef _LVM_XLATE_H
19 #define _LVM_XLATE_H
20 
21 #ifdef linux
22 #  include <endian.h>
23 #  include <byteswap.h>
24 #else
25 #  include <machine/endian.h>
26 #  define bswap_16(x) (((x) & 0x00ffU) << 8 | \
27 		       ((x) & 0xff00U) >> 8)
28 #  define bswap_32(x) (((x) & 0x000000ffU) << 24 | \
29 		       ((x) & 0xff000000U) >> 24 | \
30 		       ((x) & 0x0000ff00U) << 8  | \
31 		       ((x) & 0x00ff0000U) >> 8)
32 #  define bswap_64(x) (((x) & 0x00000000000000ffULL) << 56 | \
33 		       ((x) & 0xff00000000000000ULL) >> 56 | \
34 		       ((x) & 0x000000000000ff00ULL) << 40 | \
35 		       ((x) & 0x00ff000000000000ULL) >> 40 | \
36 		       ((x) & 0x0000000000ff0000ULL) << 24 | \
37 		       ((x) & 0x0000ff0000000000ULL) >> 24 | \
38 		       ((x) & 0x00000000ff000000ULL) << 8 | \
39 		       ((x) & 0x000000ff00000000ULL) >> 8)
40 #endif
41 
42 #if BYTE_ORDER == LITTLE_ENDIAN
43 #  define xlate16(x) (x)
44 #  define xlate32(x) (x)
45 #  define xlate64(x) (x)
46 #  define xlate16_be(x) bswap_16(x)
47 #  define xlate32_be(x) bswap_32(x)
48 #  define xlate64_be(x) bswap_64(x)
49 #elif BYTE_ORDER == BIG_ENDIAN
50 #  define xlate16(x) bswap_16(x)
51 #  define xlate32(x) bswap_32(x)
52 #  define xlate64(x) bswap_64(x)
53 #  define xlate16_be(x) (x)
54 #  define xlate32_be(x) (x)
55 #  define xlate64_be(x) (x)
56 #else
57 #  include <asm/byteorder.h>
58 #  define xlate16(x) __cpu_to_le16((x))
59 #  define xlate32(x) __cpu_to_le32((x))
60 #  define xlate64(x) __cpu_to_le64((x))
61 #  define xlate16_be(x) __cpu_to_be16((x))
62 #  define xlate32_be(x) __cpu_to_be32((x))
63 #  define xlate64_be(x) __cpu_to_be64((x))
64 #endif
65 
66 #endif
67