Use Client_find_by_session() instead of a few open-coded loops.
[umurmur.git] / src / byteorder.h
1 /* Copyright (C) 2014, Felix Morgner <felix.morgner@gmail.com>
2    Copyright (C) 2009-2014, Martin Johansson <martin@fatbob.nu>
3    Copyright (C) 2005-2014, Thorvald Natvig <thorvald@natvig.com>
4
5    All rights reserved.
6
7    Redistribution and use in source and binary forms, with or without
8    modification, are permitted provided that the following conditions
9    are met:
10
11    - Redistributions of source code must retain the above copyright notice,
12      this list of conditions and the following disclaimer.
13    - Redistributions in binary form must reproduce the above copyright notice,
14      this list of conditions and the following disclaimer in the documentation
15      and/or other materials provided with the distribution.
16    - Neither the name of the Developers nor the names of its contributors may
17      be used to endorse or promote products derived from this software without
18      specific prior written permission.
19
20    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
24    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef BYTEORDER_H_
34 #define BYTEORDER_H_
35
36 #include <stdint.h>
37
38 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
39 #include <machine/endian.h>
40 #if BYTE_ORDER == BIG_ENDIAN
41 #define BYTE_ORDER_BIG_ENDIAN
42 #endif // BYTE_ORDER == BIG_ENDIAN
43 #elif defined(LINUX)
44 #include <endian.h>
45 #if __BYTE_ORDER == __BIG_ENDIAN
46 #define BYTE_ORDER_BIG_ENDIAN
47 #endif // __BYTE_ORDER == __BIG_ENDIAN
48 #endif // defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
49
50 #if defined(__LP64__)
51 #define BLOCKSIZE 2
52 #define SHIFTBITS 63
53 typedef uint64_t subblock;
54 #if defined(BYTE_ORDER_BIG_ENDIAN)
55 #define SWAPPED(x) (x)
56 #elif defined( __x86_64__)
57 #define SWAPPED(x) ({register uint64_t __out, __in = (x); __asm__("bswap %q0" : "=r"(__out) : "0"(__in)); __out;})
58 #else
59 #include <byteswap.h>
60 #define SWAPPED(x) bswap_64(x)
61 #endif // defined(BYTE_ORDER_BIG_ENDIAN)
62 #else
63 #define BLOCKSIZE 4
64 #define SHIFTBITS 31
65 typedef uint32_t subblock;
66 #define SWAPPED(x) htonl(x)
67 #endif // defined(__LP64__)
68
69 #define HIGHBIT (1<<SHIFTBITS);
70
71 #endif // BYTEORDER_H_