1 /*-
2  * Copyright (c) 2000-2005 MAEKAWA Masahide <maekawa@cvsync.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the author nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef __BASEDEF_H__
31 #define	__BASEDEF_H__
32 
33 #define	GetWord(w)	((((uint16_t)((w)[0])) << 8) | \
34 			 (((uint16_t)((w)[1])) << 0))
35 
36 #define	GetDWord(w)	((((uint32_t)((w)[0])) << 24) | \
37 			 (((uint32_t)((w)[1])) << 16) | \
38 			 (((uint32_t)((w)[2])) <<  8) | \
39 			 (((uint32_t)((w)[3])) <<  0))
40 
41 #define	GetDDWord(w)	((((uint64_t)((w)[0])) << 56) | \
42 			 (((uint64_t)((w)[1])) << 48) | \
43 			 (((uint64_t)((w)[2])) << 40) | \
44 			 (((uint64_t)((w)[3])) << 32) | \
45 			 (((uint64_t)((w)[4])) << 24) | \
46 			 (((uint64_t)((w)[5])) << 16) | \
47 			 (((uint64_t)((w)[6])) <<  8) | \
48 			 (((uint64_t)((w)[7])) <<  0))
49 
50 #define	SetWord(w, v) \
51 	do { \
52 		(w)[0] = (uint8_t)((uint16_t)(v) >> 8); \
53 		(w)[1] = (uint8_t)((uint16_t)(v) >> 0); \
54 	} while (/* CONSTCOND */ 0)
55 
56 #define	SetDWord(w, v) \
57 	do { \
58 		(w)[0] = (uint8_t)((uint32_t)(v) >> 24); \
59 		(w)[1] = (uint8_t)((uint32_t)(v) >> 16); \
60 		(w)[2] = (uint8_t)((uint32_t)(v) >>  8); \
61 		(w)[3] = (uint8_t)((uint32_t)(v) >>  0); \
62 	} while (/* CONSTCOND */ 0)
63 
64 #define	SetDDWord(w, v) \
65 	do { \
66 		(w)[0] = (uint8_t)((uint64_t)(v) >> 56); \
67 		(w)[1] = (uint8_t)((uint64_t)(v) >> 48); \
68 		(w)[2] = (uint8_t)((uint64_t)(v) >> 40); \
69 		(w)[3] = (uint8_t)((uint64_t)(v) >> 32); \
70 		(w)[4] = (uint8_t)((uint64_t)(v) >> 24); \
71 		(w)[5] = (uint8_t)((uint64_t)(v) >> 16); \
72 		(w)[6] = (uint8_t)((uint64_t)(v) >>  8); \
73 		(w)[7] = (uint8_t)((uint64_t)(v) >>  0); \
74 	} while (/* CONSTCOND */ 0)
75 
76 #endif /* __BASEDEF_H__ */
77