File: mkc_bswap.h

package info (click to toggle)
mk-configure 0.37.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,112 kB
  • sloc: ansic: 5,441; makefile: 1,412; sh: 1,086; cpp: 200; perl: 101; yacc: 85; lex: 21
file content (54 lines) | stat: -rw-r--r-- 1,447 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/********************************************************************\
 Copyright (c) 2017 by Aleksey Cheusov

 See LICENSE file in the distribution.
\********************************************************************/

#ifndef _MKC_BSWAP_H_
#define _MKC_BSWAP_H_

#ifndef _MKC_CHECK_BSWAP
# error "Missing MKC_FEATURES += bswap"
#endif

#if HAVE_FUNC1_BSWAP_16_BYTESWAP_H && \
	HAVE_FUNC1_BSWAP_32_BYTESWAP_H && \
	HAVE_FUNC1_BSWAP_64_BYTESWAP_H
#include <byteswap.h>
#define bswap16(v) bswap_16(v)
#define bswap32(v) bswap_32(v)
#define bswap64(v) bswap_64(v)
#elif HAVE_FUNC1_BSWAP16_SYS_ENDIAN_H && \
	HAVE_FUNC1_BSWAP32_SYS_ENDIAN_H && \
	HAVE_FUNC1_BSWAP64_SYS_ENDIAN_H
#include <sys/endian.h>
#else

#include <stdint.h>

#define bswap16(x) \
    (uint16_t)( \
    (((x) & 0xff00) >> 8) | \
    (((x) & 0x00ff) << 8))

#define bswap32(x) \
    (uint32_t)( \
    (((x) & 0xff000000) >> 24) | \
    (((x) & 0x00ff0000) >> 8) | \
    (((x) & 0x0000ff00) << 8) | \
    (((x) & 0x000000ff) << 24))

#define bswap64(x) \
    (uint64_t)( \
    (((x) & 0xff00000000000000ull) >> 56) | \
    (((x) & 0x00ff000000000000ull) >> 40) | \
    (((x) & 0x0000ff0000000000ull) >> 24) | \
    (((x) & 0x000000ff00000000ull) >>  8) | \
    (((x) & 0x00000000ff000000ull) <<  8) | \
    (((x) & 0x0000000000ff0000ull) << 24) | \
    (((x) & 0x000000000000ff00ull) << 40) | \
    (((x) & 0x00000000000000ffull) << 56))

#endif /**/

#endif /* _MKC_BSWAP_H_ */