10cc8b6ece4b3e757e11a906a81ece292437713abarmvixl// Copyright 2015, ARM Limited
2ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// All rights reserved.
3ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//
4ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// Redistribution and use in source and binary forms, with or without
5ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// modification, are permitted provided that the following conditions are met:
6ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//
7ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//   * Redistributions of source code must retain the above copyright notice,
8ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//     this list of conditions and the following disclaimer.
9ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//   * Redistributions in binary form must reproduce the above copyright notice,
10ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//     this list of conditions and the following disclaimer in the documentation
11ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//     and/or other materials provided with the distribution.
12ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//   * Neither the name of ARM Limited nor the names of its contributors may be
13ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//     used to endorse or promote products derived from this software without
14ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//     specific prior written permission.
15ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl//
16ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
27ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#ifndef VIXL_GLOBALS_H
28ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#define VIXL_GLOBALS_H
29ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
30ae093bfb93c7d6b6cc143546a4211995a9db4ebfarmvixl// Get standard C99 macros for integer types.
311123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl#ifndef __STDC_CONSTANT_MACROS
321123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl#define __STDC_CONSTANT_MACROS
331123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl#endif
341123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl
35ae093bfb93c7d6b6cc143546a4211995a9db4ebfarmvixl#ifndef __STDC_LIMIT_MACROS
36ae093bfb93c7d6b6cc143546a4211995a9db4ebfarmvixl#define __STDC_LIMIT_MACROS
37ae093bfb93c7d6b6cc143546a4211995a9db4ebfarmvixl#endif
38ae093bfb93c7d6b6cc143546a4211995a9db4ebfarmvixl
39ae093bfb93c7d6b6cc143546a4211995a9db4ebfarmvixl#ifndef __STDC_FORMAT_MACROS
409b9674a6dd7b5f23d73a5432b74affe4bc380c31Serban Constantinescu#define __STDC_FORMAT_MACROS
41ae093bfb93c7d6b6cc143546a4211995a9db4ebfarmvixl#endif
42ae093bfb93c7d6b6cc143546a4211995a9db4ebfarmvixl
438fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#ifdef __ANDROID__
448fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#ifndef LOG_TAG
458fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#define LOG_TAG   "VIXL"
468fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#endif
478fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#include <cutils/log.h>
488fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#endif
498fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu
50ae093bfb93c7d6b6cc143546a4211995a9db4ebfarmvixl#include <stdint.h>
51ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#include <inttypes.h>
52ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
53ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#include <assert.h>
54ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#include <stdarg.h>
55ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#include <stdio.h>
56ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#include <stdint.h>
57ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#include <stdlib.h>
58ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#include <stddef.h>
590cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#include "vixl/platform.h"
60ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
61ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
62ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixltypedef uint8_t byte;
63ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
640cc8b6ece4b3e757e11a906a81ece292437713abarmvixl// Type for half-precision (16 bit) floating point numbers.
650cc8b6ece4b3e757e11a906a81ece292437713abarmvixltypedef uint16_t float16;
660cc8b6ece4b3e757e11a906a81ece292437713abarmvixl
67ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlconst int KBytes = 1024;
68ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlconst int MBytes = 1024 * KBytes;
69ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
708fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#ifdef __ANDROID__
718fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu  #define VIXL_ABORT() ALOGE("in %s, line %i", __FILE__, __LINE__); abort()
728fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#else
738fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu  #define VIXL_ABORT() printf("in %s, line %i", __FILE__, __LINE__); abort()
748fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#endif
758fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu
764a06316541258e3c058792321295ee36d409f419armvixl#ifdef VIXL_DEBUG
771123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_ASSERT(condition) assert(condition)
781123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_CHECK(condition) VIXL_ASSERT(condition)
790cc8b6ece4b3e757e11a906a81ece292437713abarmvixl  #ifdef __ANDROID__
800cc8b6ece4b3e757e11a906a81ece292437713abarmvixl    #define VIXL_UNIMPLEMENTED() ALOGD("UNIMPLEMENTED\t"); VIXL_ABORT()
810cc8b6ece4b3e757e11a906a81ece292437713abarmvixl    #define VIXL_UNREACHABLE() ALOGD("UNREACHABLE\t"); VIXL_ABORT()
820cc8b6ece4b3e757e11a906a81ece292437713abarmvixl  #else
830cc8b6ece4b3e757e11a906a81ece292437713abarmvixl    #define VIXL_UNIMPLEMENTED() printf("UNIMPLEMENTED\t"); VIXL_ABORT()
840cc8b6ece4b3e757e11a906a81ece292437713abarmvixl    #define VIXL_UNREACHABLE() printf("UNREACHABLE\t"); VIXL_ABORT()
850cc8b6ece4b3e757e11a906a81ece292437713abarmvixl  #endif
86ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#else
871123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_ASSERT(condition) ((void) 0)
881123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_CHECK(condition) assert(condition)
891123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_UNIMPLEMENTED() ((void) 0)
901123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_UNREACHABLE() ((void) 0)
91ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#endif
921123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl// This is not as powerful as template based assertions, but it is simple.
931123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl// It assumes that the descriptions are unique. If this starts being a problem,
941123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl// we can switch to a different implemention.
951123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl#define VIXL_CONCAT(a, b) a##b
961123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl#define VIXL_STATIC_ASSERT_LINE(line, condition) \
971123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  typedef char VIXL_CONCAT(STATIC_ASSERT_LINE_, line)[(condition) ? 1 : -1] \
981123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  __attribute__((unused))
991123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl#define VIXL_STATIC_ASSERT(condition) VIXL_STATIC_ASSERT_LINE(__LINE__, condition) //NOLINT
100ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
101ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixltemplate <typename T> inline void USE(T) {}
1020cc8b6ece4b3e757e11a906a81ece292437713abarmvixltemplate <typename T> inline void USE(T, T) {}
1030cc8b6ece4b3e757e11a906a81ece292437713abarmvixltemplate <typename T> inline void USE(T, T, T) {}
1040cc8b6ece4b3e757e11a906a81ece292437713abarmvixltemplate <typename T> inline void USE(T, T, T, T) {}
105ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
1068fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#ifdef __ANDROID__
1070cc8b6ece4b3e757e11a906a81ece292437713abarmvixl  #define VIXL_ALIGNMENT_EXCEPTION() ALOGD("ALIGNMENT EXCEPTION\t"); VIXL_ABORT() //NOLINT
1080cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#else
1090cc8b6ece4b3e757e11a906a81ece292437713abarmvixl  #define VIXL_ALIGNMENT_EXCEPTION() printf("ALIGNMENT EXCEPTION\t"); VIXL_ABORT() //NOLINT
1100cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#endif
1110cc8b6ece4b3e757e11a906a81ece292437713abarmvixl
1120cc8b6ece4b3e757e11a906a81ece292437713abarmvixl// The clang::fallthrough attribute is used along with the Wimplicit-fallthrough
1130cc8b6ece4b3e757e11a906a81ece292437713abarmvixl// argument to annotate intentional fall-through between switch labels.
1140cc8b6ece4b3e757e11a906a81ece292437713abarmvixl// For more information please refer to:
1150cc8b6ece4b3e757e11a906a81ece292437713abarmvixl// http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
1160cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#ifndef __has_warning
1170cc8b6ece4b3e757e11a906a81ece292437713abarmvixl  #define __has_warning(x)  0
1180cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#endif
1190cc8b6ece4b3e757e11a906a81ece292437713abarmvixl
1200cc8b6ece4b3e757e11a906a81ece292437713abarmvixl// Note: This option is only available for Clang. And will only be enabled for
1210cc8b6ece4b3e757e11a906a81ece292437713abarmvixl// C++11(201103L).
1220cc8b6ece4b3e757e11a906a81ece292437713abarmvixl#if __has_warning("-Wimplicit-fallthrough") && __cplusplus >= 201103L
1230cc8b6ece4b3e757e11a906a81ece292437713abarmvixl  #define VIXL_FALLTHROUGH() [[clang::fallthrough]] //NOLINT
1248fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#else
1250cc8b6ece4b3e757e11a906a81ece292437713abarmvixl  #define VIXL_FALLTHROUGH() do {} while (0)
1268fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#endif
127ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
128ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#endif  // VIXL_GLOBALS_H
129