Home | History | Annotate | Download | only in wtf
      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_TRADITIONAL) - Thumb2 is not available, only traditional ARM (v4 or greater) */
    147 /* CPU(ARM_THUMB2) - Thumb2 instruction set is available */
    148 /* Only one of these will be defined. */
    149 #if !defined(WTF_CPU_ARM_TRADITIONAL) && !defined(WTF_CPU_ARM_THUMB2)
    150 #  if defined(thumb2) || defined(__thumb2__) \
    151     || ((defined(__thumb) || defined(__thumb__)) && WTF_THUMB_ARCH_VERSION == 4)
    152 #    define WTF_CPU_ARM_TRADITIONAL 0
    153 #    define WTF_CPU_ARM_THUMB2 1
    154 #  elif WTF_ARM_ARCH_AT_LEAST(4)
    155 #    define WTF_CPU_ARM_TRADITIONAL 1
    156 #    define WTF_CPU_ARM_THUMB2 0
    157 #  else
    158 #    error "Not supported ARM architecture"
    159 #  endif
    160 #elif CPU(ARM_TRADITIONAL) && CPU(ARM_THUMB2) /* Sanity Check */
    161 #  error "Cannot use both of WTF_CPU_ARM_TRADITIONAL and WTF_CPU_ARM_THUMB2 platforms"
    162 #endif /* !defined(WTF_CPU_ARM_TRADITIONAL) && !defined(WTF_CPU_ARM_THUMB2) */
    163 
    164 #if defined(__ARM_NEON__) && !defined(WTF_CPU_ARM_NEON)
    165 #define WTF_CPU_ARM_NEON 1
    166 #endif
    167 
    168 #if CPU(ARM_NEON) && (!COMPILER(GCC) || GCC_VERSION_AT_LEAST(4, 7, 0))
    169 // All NEON intrinsics usage can be disabled by this macro.
    170 #define HAVE_ARM_NEON_INTRINSICS 1
    171 #endif
    172 
    173 #if defined(__ARM_ARCH_7S__)
    174 #define WTF_CPU_APPLE_ARMV7S 1
    175 #endif
    176 
    177 #if !defined(WTF_CPU_64BIT)
    178 #define WTF_CPU_32BIT 1
    179 #endif
    180 
    181 #endif /* ARM */
    182 
    183 #endif /* WTF_CPU_h */
    184