|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2022 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // bswap マクロの OS ごとに違う部分を吸収する
9: //
10:
11: // bswapNN() 系は
12: // - NetBSD, FreeBSD では <sys/endian.h> に bswapNN()。
13: // - OpenBSD では <sys/endian.h> に swapNN() (bがない)。
14: // - Linux では <byteswap.h> に bswap_NN() (アンダースコアがある)。
15: // - OSX では <libkern/OSByteOrder.h> の OSSwap{Const,}IntNN()。
16:
17: #pragma once
18:
19: #include "config-nono.h"
20:
21: #if defined(HAVE_BYTESWAP_H)
22: #include <byteswap.h> // bswap_NN() on Linux
23: #endif
24: #if defined(HAVE_SYS_ENDIAN_H)
25: #include <sys/endian.h> // bswapNN/swapNN on *BSD
26: #endif
27:
28: // __builtin_bswap* がないような環境があったらその時考える
29:
30: #if defined(HAVE_BSWAP16)
31: #elif defined(HAVE_BSWAP_16)
32: # define bswap16(x) bswap_16(x)
33: #elif defined(HAVE_SWAP16)
34: # define bswap16(x) swap16(x)
35: #elif defined(HAVE___BUILTIN_BSWAP16)
36: # define bswap16(x) __builtin_bswap16(x)
37: #else
38: #error No bswap16 found
39: #endif
40:
41: #if defined(HAVE_BSWAP32)
42: #elif defined(HAVE_BSWAP_32)
43: # define bswap32(x) bswap_32(x)
44: #elif defined(HAVE_SWAP32)
45: # define bswap32(x) swap32(x)
46: #elif defined(HAVE___BUILTIN_BSWAP32)
47: # define bswap32(x) __builtin_bswap32(x)
48: #else
49: #error No bswap32 found
50: #endif
51:
52: #if defined(HAVE_BSWAP64)
53: #elif defined(HAVE_BSWAP_64)
54: # define bswap64(x) bswap_64(x)
55: #elif defined(HAVE_SWAP64)
56: # define bswap64(x) swap64(x)
57: #elif defined(HAVE___BUILTIN_BSWAP64)
58: # define bswap64(x) __builtin_bswap64(x)
59: #else
60: #error No bswap64 found
61: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.