Initial revision
[silc.git] / includes / bitmove.h
1 /*
2
3   bitmove.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20
21 #ifndef BITMOVE_H
22 #define BITMOVE_H
23
24 /* Returns four 8-bit bytes, most significant bytes first. */
25 #define SILC_GET32_MSB(l, cp) \
26         (l) = ((unsigned long)(unsigned char)(cp)[0]) << 24 \
27             | ((unsigned long)(unsigned char)(cp)[1] << 16) \
28             | ((unsigned long)(unsigned char)(cp)[2] << 8) \
29             | ((unsigned long)(unsigned char)(cp)[3])
30 #define SILC_PUT32_MSB(l, cp) \
31         (cp)[0] = l >> 24; \
32         (cp)[1] = l >> 16; \
33         (cp)[2] = l >> 8; \
34         (cp)[3] = l;
35
36
37 /* Returns four 8-bit bytes, less significant bytes first. */
38 #define SILC_GET32_LSB(l, cp) \
39         (l) = ((unsigned long)(unsigned char)(cp)[0]) \
40             | ((unsigned long)(unsigned char)(cp)[1] << 8) \
41             | ((unsigned long)(unsigned char)(cp)[2] << 16) \
42             | ((unsigned long)(unsigned char)(cp)[3] << 24)
43 /* same as upper but XOR the result always */
44 #define SILC_GET32_X_LSB(l, cp) \
45         (l) ^= ((unsigned long)(unsigned char)(cp)[0]) \
46             | ((unsigned long)(unsigned char)(cp)[1] << 8) \
47             | ((unsigned long)(unsigned char)(cp)[2] << 16) \
48             | ((unsigned long)(unsigned char)(cp)[3] << 24)
49 #define SILC_PUT32_LSB(l, cp) \
50         (cp)[0] = l; \
51         (cp)[1] = l >> 8; \
52         (cp)[2] = l >> 16; \
53         (cp)[3] = l >> 24;
54
55
56 /* Returns two 8-bit bytes, most significant bytes first. */
57 #define SILC_GET16_MSB(l, cp) \
58         (l) = ((unsigned long)(unsigned char)(cp)[0] << 8) \
59             | ((unsigned long)(unsigned char)(cp)[1])
60 #define SILC_PUT16_MSB(l, cp) \
61         (cp)[0] = l >> 8; \
62         (cp)[1] = l;
63
64 /* Returns two 8-bit bytes, less significant bytes first. */
65 #define SILC_GET16_LSB(l, cp) \
66         (l) = ((unsigned long)(unsigned char)(cp)[0]) \
67             | ((unsigned long)(unsigned char)(cp)[1] << 8)
68 #define SILC_PUT16_LSB(l, cp) \
69         (cp)[0] = l; \
70         (cp)[1] = l >> 8;
71
72 #endif