2 * Copyright © 2000 SuSE, Inc.
3 * Copyright © 2007 Red Hat, Inc.
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of SuSE not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. SuSE makes no representations about the
12 * suitability of this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
15 * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
17 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 #include "pixman-private.h"
37 #if defined(USE_ARM_SIMD) || defined(USE_ARM_NEON) || defined(USE_ARM_IWMMXT)
41 /* Needed for EXCEPTION_ILLEGAL_INSTRUCTION */
44 extern int pixman_msvc_try_arm_neon_op ();
45 extern int pixman_msvc_try_arm_simd_op ();
47 static arm_cpu_features_t
48 detect_cpu_features (void)
50 arm_cpu_features_t features = 0;
54 pixman_msvc_try_arm_simd_op ();
57 __except (GetExceptionCode () == EXCEPTION_ILLEGAL_INSTRUCTION)
63 pixman_msvc_try_arm_neon_op ();
66 __except (GetExceptionCode () == EXCEPTION_ILLEGAL_INSTRUCTION)
73 #elif defined(__APPLE__) && defined(TARGET_OS_IPHONE) /* iOS */
75 #include "TargetConditionals.h"
77 static arm_cpu_features_t
78 detect_cpu_features (void)
80 arm_cpu_features_t features = 0;
84 /* Detection of ARM NEON on iOS is fairly simple because iOS binaries
85 * contain separate executable images for each processor architecture.
86 * So all we have to do is detect the armv7 architecture build. The
87 * operating system automatically runs the armv7 binary for armv7 devices
88 * and the armv6 binary for armv6 devices.
90 #if defined(__ARM_NEON__)
97 #elif defined(__ANDROID__) || defined(ANDROID) /* Android */
99 #include <cpu-features.h>
101 static arm_cpu_features_t
102 detect_cpu_features (void)
104 arm_cpu_features_t features = 0;
105 AndroidCpuFamily cpu_family;
106 uint64_t cpu_features;
108 cpu_family = android_getCpuFamily();
109 cpu_features = android_getCpuFeatures();
111 if (cpu_family == ANDROID_CPU_FAMILY_ARM)
113 if (cpu_features & ANDROID_CPU_ARM_FEATURE_ARMv7)
116 if (cpu_features & ANDROID_CPU_ARM_FEATURE_VFPv3)
119 if (cpu_features & ANDROID_CPU_ARM_FEATURE_NEON)
120 features |= ARM_NEON;
126 #elif defined (__linux__) /* linux ELF */
129 #include <sys/types.h>
130 #include <sys/stat.h>
131 #include <sys/mman.h>
136 static arm_cpu_features_t
137 detect_cpu_features (void)
139 arm_cpu_features_t features = 0;
143 fd = open ("/proc/self/auxv", O_RDONLY);
146 while (read (fd, &aux, sizeof(Elf32_auxv_t)) == sizeof(Elf32_auxv_t))
148 if (aux.a_type == AT_HWCAP)
150 uint32_t hwcap = aux.a_un.a_val;
152 /* hardcode these values to avoid depending on specific
153 * versions of the hwcap header, e.g. HWCAP_NEON
155 if ((hwcap & 64) != 0)
157 if ((hwcap & 512) != 0)
158 features |= ARM_IWMMXT;
159 /* this flag is only present on kernel 2.6.29 */
160 if ((hwcap & 4096) != 0)
161 features |= ARM_NEON;
163 else if (aux.a_type == AT_PLATFORM)
165 const char *plat = (const char*) aux.a_un.a_val;
167 if (strncmp (plat, "v7l", 3) == 0)
168 features |= (ARM_V7 | ARM_V6);
169 else if (strncmp (plat, "v6l", 3) == 0)
181 static arm_cpu_features_t
182 detect_cpu_features (void)
187 #endif /* Linux elf */
190 have_feature (arm_cpu_features_t feature)
192 static pixman_bool_t initialized;
193 static arm_cpu_features_t features;
197 features = detect_cpu_features();
201 return (features & feature) == feature;
204 #endif /* USE_ARM_SIMD || USE_ARM_NEON || USE_ARM_IWMMXT */
206 pixman_implementation_t *
207 _pixman_arm_get_implementations (pixman_implementation_t *imp)
210 if (!_pixman_disabled ("arm-simd") && have_feature (ARM_V6))
211 imp = _pixman_implementation_create_arm_simd (imp);
214 #ifdef USE_ARM_IWMMXT
215 if (!_pixman_disabled ("arm-iwmmxt") && have_feature (ARM_IWMMXT))
216 imp = _pixman_implementation_create_mmx (imp);
220 if (!_pixman_disabled ("arm-neon") && have_feature (ARM_NEON))
221 imp = _pixman_implementation_create_arm_neon (imp);