1/*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2007-2009 Torch Mobile, Inc.
4 * Copyright (C) 2010, 2011 Research In Motion Limited. All rights reserved.
5 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef WTF_CPU_h
30#define WTF_CPU_h
31
32#include "wtf/Compiler.h"
33
34/* CPU() - the target CPU architecture */
35#define CPU(WTF_FEATURE) (defined WTF_CPU_##WTF_FEATURE  && WTF_CPU_##WTF_FEATURE)
36
37/* ==== CPU() - the target CPU architecture ==== */
38
39/* This defines CPU(BIG_ENDIAN) or nothing, as appropriate. */
40/* This defines CPU(32BIT) or CPU(64BIT), as appropriate. */
41
42/* CPU(X86) - i386 / x86 32-bit */
43#if   defined(__i386__) \
44    || defined(i386)     \
45    || defined(_M_IX86)  \
46    || defined(_X86_)    \
47    || defined(__THW_INTEL)
48#define WTF_CPU_X86 1
49#endif
50
51/* CPU(X86_64) - AMD64 / Intel64 / x86_64 64-bit */
52#if   defined(__x86_64__) \
53    || defined(_M_X64)
54#define WTF_CPU_X86_64 1
55#define WTF_CPU_64BIT 1
56#endif
57
58/* CPU(ARM) - ARM, any version*/
59#define WTF_ARM_ARCH_AT_LEAST(N) (CPU(ARM) && defined(WTF_ARM_ARCH_VERSION) && WTF_ARM_ARCH_VERSION >= N)
60
61#if   defined(arm) \
62    || defined(__arm__) \
63    || defined(ARM) \
64    || defined(_ARM_)
65#define WTF_CPU_ARM 1
66
67#if defined(__ARMEB__)
68#define WTF_CPU_BIG_ENDIAN 1
69
70#elif !defined(__ARM_EABI__) \
71    && !defined(__EABI__) \
72    && !defined(__VFP_FP__) \
73    && !defined(_WIN32_WCE) \
74    && !defined(ANDROID)
75#define WTF_CPU_MIDDLE_ENDIAN 1
76
77#endif
78
79/* Set WTF_ARM_ARCH_VERSION */
80#if   defined(__ARM_ARCH_4__) \
81    || defined(__ARM_ARCH_4T__) \
82    || defined(__MARM_ARMV4__)
83#define WTF_ARM_ARCH_VERSION 4
84
85#elif defined(__ARM_ARCH_5__) \
86    || defined(__ARM_ARCH_5T__) \
87    || defined(__MARM_ARMV5__)
88#define WTF_ARM_ARCH_VERSION 5
89
90#elif defined(__ARM_ARCH_5E__) \
91    || defined(__ARM_ARCH_5TE__) \
92    || defined(__ARM_ARCH_5TEJ__)
93#define WTF_ARM_ARCH_VERSION 5
94
95#elif defined(__ARM_ARCH_6__) \
96    || defined(__ARM_ARCH_6J__) \
97    || defined(__ARM_ARCH_6K__) \
98    || defined(__ARM_ARCH_6Z__) \
99    || defined(__ARM_ARCH_6ZK__) \
100    || defined(__ARM_ARCH_6T2__) \
101    || defined(__ARMV6__)
102#define WTF_ARM_ARCH_VERSION 6
103
104#elif defined(__ARM_ARCH_7A__) \
105    || defined(__ARM_ARCH_7R__) \
106    || defined(__ARM_ARCH_7S__)
107#define WTF_ARM_ARCH_VERSION 7
108
109/* MSVC sets _M_ARM */
110#elif defined(_M_ARM)
111#define WTF_ARM_ARCH_VERSION _M_ARM
112#else
113#define WTF_ARM_ARCH_VERSION 0
114
115#endif
116
117/* Set WTF_THUMB_ARCH_VERSION */
118#if   defined(__ARM_ARCH_4T__)
119#define WTF_THUMB_ARCH_VERSION 1
120
121#elif defined(__ARM_ARCH_5T__) \
122    || defined(__ARM_ARCH_5TE__) \
123    || defined(__ARM_ARCH_5TEJ__)
124#define WTF_THUMB_ARCH_VERSION 2
125
126#elif defined(__ARM_ARCH_6J__) \
127    || defined(__ARM_ARCH_6K__) \
128    || defined(__ARM_ARCH_6Z__) \
129    || defined(__ARM_ARCH_6ZK__) \
130    || defined(__ARM_ARCH_6M__)
131#define WTF_THUMB_ARCH_VERSION 3
132
133#elif defined(__ARM_ARCH_6T2__) \
134    || defined(__ARM_ARCH_7__) \
135    || defined(__ARM_ARCH_7A__) \
136    || defined(__ARM_ARCH_7M__) \
137    || defined(__ARM_ARCH_7R__) \
138    || defined(__ARM_ARCH_7S__)
139#define WTF_THUMB_ARCH_VERSION 4
140
141#else
142#define WTF_THUMB_ARCH_VERSION 0
143#endif
144
145
146/* CPU(ARM_THUMB2) - Thumb2 instruction set is available */
147#if !defined(WTF_CPU_ARM_THUMB2)
148#  if defined(thumb2) || defined(__thumb2__) \
149    || ((defined(__thumb) || defined(__thumb__)) && WTF_THUMB_ARCH_VERSION == 4)
150#    define WTF_CPU_ARM_THUMB2 1
151#  elif WTF_ARM_ARCH_AT_LEAST(4)
152#    define WTF_CPU_ARM_THUMB2 0
153#  else
154#    error "Unsupported ARM architecture"
155#  endif
156#endif /* !defined(WTF_CPU_ARM_THUMB2) */
157
158#if defined(__ARM_NEON__) && !defined(WTF_CPU_ARM_NEON)
159#define WTF_CPU_ARM_NEON 1
160#endif
161
162#if CPU(ARM_NEON) && (!COMPILER(GCC) || GCC_VERSION_AT_LEAST(4, 7, 0))
163// All NEON intrinsics usage can be disabled by this macro.
164#define HAVE_ARM_NEON_INTRINSICS 1
165#endif
166
167#if defined(__ARM_ARCH_7S__)
168#define WTF_CPU_APPLE_ARMV7S 1
169#endif
170
171#if !defined(WTF_CPU_64BIT)
172#define WTF_CPU_32BIT 1
173#endif
174
175#endif /* ARM */
176
177/* CPU(ARM64) - AArch64 64-bit */
178#if defined(__aarch64__)
179#define WTF_CPU_ARM64 1
180#define WTF_CPU_64BIT 1
181#endif
182
183/* This defines CPU(64BIT). */
184#if defined(__mips__) && (_MIPS_SIM == _ABI64)
185#define WTF_CPU_64BIT 1
186#endif
187
188#endif /* WTF_CPU_h */
189