1 // Copyright 2015, ARM Limited
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright notice,
10 // this list of conditions and the following disclaimer in the documentation
11 // and/or other materials provided with the distribution.
12 // * Neither the name of ARM Limited nor the names of its contributors may be
13 // used to endorse or promote products derived from this software without
14 // specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 #ifndef VIXL_GLOBALS_H
28 #define VIXL_GLOBALS_H
29
30 // Get standard C99 macros for integer types.
31 #ifndef __STDC_CONSTANT_MACROS
32 #define __STDC_CONSTANT_MACROS
33 #endif
34
35 #ifndef __STDC_LIMIT_MACROS
36 #define __STDC_LIMIT_MACROS
37 #endif
38
39 #ifndef __STDC_FORMAT_MACROS
40 #define __STDC_FORMAT_MACROS
41 #endif
42
43 #ifdef __ANDROID__
44 #ifndef LOG_TAG
45 #define LOG_TAG "VIXL"
46 #endif
47 #include <cutils/log.h>
48 #endif
49
50 #include <stdint.h>
51 #include <inttypes.h>
52
53 #include <assert.h>
54 #include <stdarg.h>
55 #include <stdio.h>
56 #include <stdint.h>
57 #include <stdlib.h>
58 #include <stddef.h>
59 #include "vixl/platform.h"
60
61
62 typedef uint8_t byte;
63
64 // Type for half-precision (16 bit) floating point numbers.
65 typedef uint16_t float16;
66
67 const int KBytes = 1024;
68 const int MBytes = 1024 * KBytes;
69
70 #ifdef __ANDROID__
71 #define VIXL_ABORT() ALOGE("in %s, line %i", __FILE__, __LINE__); abort()
72 #else
73 #define VIXL_ABORT() printf("in %s, line %i", __FILE__, __LINE__); abort()
74 #endif
75
76 #ifdef VIXL_DEBUG
77 #define VIXL_ASSERT(condition) assert(condition)
78 #define VIXL_CHECK(condition) VIXL_ASSERT(condition)
79 #ifdef __ANDROID__
80 #define VIXL_UNIMPLEMENTED() ALOGD("UNIMPLEMENTED\t"); VIXL_ABORT()
81 #define VIXL_UNREACHABLE() ALOGD("UNREACHABLE\t"); VIXL_ABORT()
82 #else
83 #define VIXL_UNIMPLEMENTED() printf("UNIMPLEMENTED\t"); VIXL_ABORT()
84 #define VIXL_UNREACHABLE() printf("UNREACHABLE\t"); VIXL_ABORT()
85 #endif
86 #else
87 #define VIXL_ASSERT(condition) ((void) 0)
88 #define VIXL_CHECK(condition) assert(condition)
89 #define VIXL_UNIMPLEMENTED() ((void) 0)
90 #define VIXL_UNREACHABLE() ((void) 0)
91 #endif
92 // This is not as powerful as template based assertions, but it is simple.
93 // It assumes that the descriptions are unique. If this starts being a problem,
94 // we can switch to a different implemention.
95 #define VIXL_CONCAT(a, b) a##b
96 #define VIXL_STATIC_ASSERT_LINE(line, condition) \
97 typedef char VIXL_CONCAT(STATIC_ASSERT_LINE_, line)[(condition) ? 1 : -1] \
98 __attribute__((unused))
99 #define VIXL_STATIC_ASSERT(condition) VIXL_STATIC_ASSERT_LINE(__LINE__, condition) //NOLINT
100
USE(T)101 template <typename T> inline void USE(T) {}
USE(T,T)102 template <typename T> inline void USE(T, T) {}
USE(T,T,T)103 template <typename T> inline void USE(T, T, T) {}
USE(T,T,T,T)104 template <typename T> inline void USE(T, T, T, T) {}
105
106 #ifdef __ANDROID__
107 #define VIXL_ALIGNMENT_EXCEPTION() ALOGD("ALIGNMENT EXCEPTION\t"); VIXL_ABORT() //NOLINT
108 #else
109 #define VIXL_ALIGNMENT_EXCEPTION() printf("ALIGNMENT EXCEPTION\t"); VIXL_ABORT() //NOLINT
110 #endif
111
112 // The clang::fallthrough attribute is used along with the Wimplicit-fallthrough
113 // argument to annotate intentional fall-through between switch labels.
114 // For more information please refer to:
115 // http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
116 #ifndef __has_warning
117 #define __has_warning(x) 0
118 #endif
119
120 // Note: This option is only available for Clang. And will only be enabled for
121 // C++11(201103L).
122 #if __has_warning("-Wimplicit-fallthrough") && __cplusplus >= 201103L
123 #define VIXL_FALLTHROUGH() [[clang::fallthrough]] //NOLINT
124 #else
125 #define VIXL_FALLTHROUGH() do {} while (0)
126 #endif
127
128 #endif // VIXL_GLOBALS_H
129