globals.h revision 4a06316541258e3c058792321295ee36d409f419
1ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// Copyright 2013, 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>
59bc4afbd2754e20d14114e4ba83f9035b26ab701dSerban Constantinescu#include "platform-vixl.h"
60ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
61ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
62ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixltypedef uint8_t byte;
63ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
64ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlconst int KBytes = 1024;
65ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlconst int MBytes = 1024 * KBytes;
66ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
678fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#ifdef __ANDROID__
688fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu  #define VIXL_ABORT() ALOGE("in %s, line %i", __FILE__, __LINE__); abort()
698fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#else
708fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu  #define VIXL_ABORT() printf("in %s, line %i", __FILE__, __LINE__); abort()
718fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#endif
728fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu
734a06316541258e3c058792321295ee36d409f419armvixl#ifdef VIXL_DEBUG
741123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_ASSERT(condition) assert(condition)
751123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_CHECK(condition) VIXL_ASSERT(condition)
768fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#ifdef __ANDROID__
778fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu  #define VIXL_UNIMPLEMENTED() ALOGD("UNIMPLEMENTED\t"); VIXL_ABORT()
788fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu  #define VIXL_UNREACHABLE() ALOGD("UNREACHABLE\t"); VIXL_ABORT()
798fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#else
801123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_UNIMPLEMENTED() printf("UNIMPLEMENTED\t"); VIXL_ABORT()
811123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_UNREACHABLE() printf("UNREACHABLE\t"); VIXL_ABORT()
828fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#endif
83ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#else
841123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_ASSERT(condition) ((void) 0)
851123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_CHECK(condition) assert(condition)
861123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_UNIMPLEMENTED() ((void) 0)
871123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  #define VIXL_UNREACHABLE() ((void) 0)
88ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#endif
891123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl// This is not as powerful as template based assertions, but it is simple.
901123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl// It assumes that the descriptions are unique. If this starts being a problem,
911123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl// we can switch to a different implemention.
921123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl#define VIXL_CONCAT(a, b) a##b
931123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl#define VIXL_STATIC_ASSERT_LINE(line, condition) \
941123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  typedef char VIXL_CONCAT(STATIC_ASSERT_LINE_, line)[(condition) ? 1 : -1] \
951123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl  __attribute__((unused))
961123fee00a9cef7f1b448eab3c2ca333dbd426d7armvixl#define VIXL_STATIC_ASSERT(condition) VIXL_STATIC_ASSERT_LINE(__LINE__, condition) //NOLINT
97ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
98ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixltemplate <typename T> inline void USE(T) {}
99ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
1008fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#ifdef __ANDROID__
1018fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu  #define VIXL_ALIGNMENT_EXCEPTION() ALOGD("ALIGNMENT EXCEPTION\t"); VIXL_ABORT()   //NOLINT
1028fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#else
1038fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu  #define VIXL_ALIGNMENT_EXCEPTION() printf("ALIGNMENT EXCEPTION\t"); VIXL_ABORT()  //NOLINT
1048fcae179b1449176c5780eb0ba57f75654ec4c80Serban Constantinescu#endif
105ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl
106ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#endif  // VIXL_GLOBALS_H
107