1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef INCLUDE_LIBYUV_BASIC_TYPES_H_  // NOLINT
13 #define INCLUDE_LIBYUV_BASIC_TYPES_H_
14 
15 #include <stddef.h>  // for NULL, size_t
16 
17 #if defined(__ANDROID__) || (defined(_MSC_VER) && (_MSC_VER < 1600))
18 #include <sys/types.h>  // for uintptr_t on x86
19 #else
20 #include <stdint.h>  // for uintptr_t
21 #endif
22 
23 #ifndef GG_LONGLONG
24 #ifndef INT_TYPES_DEFINED
25 #define INT_TYPES_DEFINED
26 #ifdef COMPILER_MSVC
27 typedef unsigned __int64 uint64;
28 typedef __int64 int64;
29 #ifndef INT64_C
30 #define INT64_C(x) x ## I64
31 #endif
32 #ifndef UINT64_C
33 #define UINT64_C(x) x ## UI64
34 #endif
35 #define INT64_F "I64"
36 #else  // COMPILER_MSVC
37 #if defined(__LP64__) && !defined(__OpenBSD__) && !defined(__APPLE__)
38 typedef unsigned long uint64;  // NOLINT
39 typedef long int64;  // NOLINT
40 #ifndef INT64_C
41 #define INT64_C(x) x ## L
42 #endif
43 #ifndef UINT64_C
44 #define UINT64_C(x) x ## UL
45 #endif
46 #define INT64_F "l"
47 #else  // defined(__LP64__) && !defined(__OpenBSD__) && !defined(__APPLE__)
48 typedef unsigned long long uint64;  // NOLINT
49 typedef long long int64;  // NOLINT
50 #ifndef INT64_C
51 #define INT64_C(x) x ## LL
52 #endif
53 #ifndef UINT64_C
54 #define UINT64_C(x) x ## ULL
55 #endif
56 #define INT64_F "ll"
57 #endif  // __LP64__
58 #endif  // COMPILER_MSVC
59 typedef unsigned int uint32;
60 typedef int int32;
61 typedef unsigned short uint16;  // NOLINT
62 typedef short int16;  // NOLINT
63 typedef unsigned char uint8;
64 typedef signed char int8;
65 #endif  // INT_TYPES_DEFINED
66 #endif  // GG_LONGLONG
67 
68 // Detect compiler is for x86 or x64.
69 #if defined(__x86_64__) || defined(_M_X64) || \
70     defined(__i386__) || defined(_M_IX86)
71 #define CPU_X86 1
72 #endif
73 // Detect compiler is for ARM.
74 #if defined(__arm__) || defined(_M_ARM)
75 #define CPU_ARM 1
76 #endif
77 
78 #ifndef ALIGNP
79 #ifdef __cplusplus
80 #define ALIGNP(p, t) \
81     (reinterpret_cast<uint8*>(((reinterpret_cast<uintptr_t>(p) + \
82     ((t) - 1)) & ~((t) - 1))))
83 #else
84 #define ALIGNP(p, t) \
85     ((uint8*)((((uintptr_t)(p) + ((t) - 1)) & ~((t) - 1))))  /* NOLINT */
86 #endif
87 #endif
88 
89 #if !defined(LIBYUV_API)
90 #if defined(_WIN32) || defined(__CYGWIN__)
91 #if defined(LIBYUV_BUILDING_SHARED_LIBRARY)
92 #define LIBYUV_API __declspec(dllexport)
93 #elif defined(LIBYUV_USING_SHARED_LIBRARY)
94 #define LIBYUV_API __declspec(dllimport)
95 #else
96 #define LIBYUV_API
97 #endif  // LIBYUV_BUILDING_SHARED_LIBRARY
98 #elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__APPLE__) && \
99     (defined(LIBYUV_BUILDING_SHARED_LIBRARY) || \
100     defined(LIBYUV_USING_SHARED_LIBRARY))
101 #define LIBYUV_API __attribute__ ((visibility ("default")))
102 #else
103 #define LIBYUV_API
104 #endif  // __GNUC__
105 #endif  // LIBYUV_API
106 
107 #define LIBYUV_BOOL int
108 #define LIBYUV_FALSE 0
109 #define LIBYUV_TRUE 1
110 
111 // Visual C x86 or GCC little endian.
112 #if defined(__x86_64__) || defined(_M_X64) || \
113   defined(__i386__) || defined(_M_IX86) || \
114   defined(__arm__) || defined(_M_ARM) || \
115   (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
116 #define LIBYUV_LITTLE_ENDIAN
117 #endif
118 
119 #endif  // INCLUDE_LIBYUV_BASIC_TYPES_H_  NOLINT
120