aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/base64/plain64/codecs.h
blob: 24cfbbc7d27094f3170cdabfbbc88186a3009189 (plain) (blame)
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
#pragma once 
 
// Define machine endianness. This is for GCC: 
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 
	#define PLAIN64_LITTLE_ENDIAN 1 
#else 
	#define PLAIN64_LITTLE_ENDIAN 0 
#endif 
 
// This is for Clang: 
#ifdef __LITTLE_ENDIAN__ 
	#define PLAIN64_LITTLE_ENDIAN 1 
#endif 
 
#ifdef __BIG_ENDIAN__ 
	#define PLAIN64_LITTLE_ENDIAN 0 
#endif 
 
// Endian conversion functions 
#if PLAIN64_LITTLE_ENDIAN 
#if defined(_WIN64) || defined(__WIN32__) || defined(_WIN32) 
	#define cpu_to_be32(x)	_byteswap_ulong(x) 
	#define cpu_to_be64(x)	_byteswap_uint64(x) 
	#define be32_to_cpu(x)	_byteswap_ulong(x) 
	#define be64_to_cpu(x)	_byteswap_uint64(x) 
#else 
	#define cpu_to_be32(x)	__builtin_bswap32(x) 
	#define cpu_to_be64(x)	__builtin_bswap64(x) 
	#define be32_to_cpu(x)	__builtin_bswap32(x) 
	#define be64_to_cpu(x)	__builtin_bswap64(x) 
#endif 
#else 
	#define cpu_to_be32(x)	(x) 
	#define cpu_to_be64(x)	(x) 
	#define be32_to_cpu(x)	(x) 
	#define be64_to_cpu(x)	(x) 
#endif 
 
// These tables are used by all codecs 
// for fallback plain encoding/decoding: 
extern const uint8_t plain64_base64_table_enc[]; 
extern const uint8_t plain64_base64_table_dec[];