1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/cairo/libpixman/src/pixman-ppc.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,155 @@ 1.4 +/* 1.5 + * Copyright © 2000 SuSE, Inc. 1.6 + * Copyright © 2007 Red Hat, Inc. 1.7 + * 1.8 + * Permission to use, copy, modify, distribute, and sell this software and its 1.9 + * documentation for any purpose is hereby granted without fee, provided that 1.10 + * the above copyright notice appear in all copies and that both that 1.11 + * copyright notice and this permission notice appear in supporting 1.12 + * documentation, and that the name of SuSE not be used in advertising or 1.13 + * publicity pertaining to distribution of the software without specific, 1.14 + * written prior permission. SuSE makes no representations about the 1.15 + * suitability of this software for any purpose. It is provided "as is" 1.16 + * without express or implied warranty. 1.17 + * 1.18 + * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 1.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE 1.20 + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1.21 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 1.22 + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 1.23 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1.24 + */ 1.25 +#ifdef HAVE_CONFIG_H 1.26 +#include <config.h> 1.27 +#endif 1.28 + 1.29 +#include "pixman-private.h" 1.30 + 1.31 +#ifdef USE_VMX 1.32 + 1.33 +/* The CPU detection code needs to be in a file not compiled with 1.34 + * "-maltivec -mabi=altivec", as gcc would try to save vector register 1.35 + * across function calls causing SIGILL on cpus without Altivec/vmx. 1.36 + */ 1.37 +#ifdef __APPLE__ 1.38 +#include <sys/sysctl.h> 1.39 + 1.40 +static pixman_bool_t 1.41 +pixman_have_vmx (void) 1.42 +{ 1.43 + int error, have_vmx; 1.44 + size_t length = sizeof(have_vmx); 1.45 + 1.46 + error = sysctlbyname ("hw.optional.altivec", &have_vmx, &length, NULL, 0); 1.47 + 1.48 + if (error) 1.49 + return FALSE; 1.50 + 1.51 + return have_vmx; 1.52 +} 1.53 + 1.54 +#elif defined (__OpenBSD__) 1.55 +#include <sys/param.h> 1.56 +#include <sys/sysctl.h> 1.57 +#include <machine/cpu.h> 1.58 + 1.59 +static pixman_bool_t 1.60 +pixman_have_vmx (void) 1.61 +{ 1.62 + int error, have_vmx; 1.63 + int mib[2] = { CTL_MACHDEP, CPU_ALTIVEC }; 1.64 + size_t length = sizeof(have_vmx); 1.65 + 1.66 + error = sysctl (mib, 2, &have_vmx, &length, NULL, 0); 1.67 + 1.68 + if (error != 0) 1.69 + return FALSE; 1.70 + 1.71 + return have_vmx; 1.72 +} 1.73 + 1.74 +#elif defined (__linux__) 1.75 + 1.76 +#include <sys/types.h> 1.77 +#include <sys/stat.h> 1.78 +#include <fcntl.h> 1.79 +#include <unistd.h> 1.80 +#include <stdio.h> 1.81 +#include <linux/auxvec.h> 1.82 +#include <asm/cputable.h> 1.83 + 1.84 +static pixman_bool_t 1.85 +pixman_have_vmx (void) 1.86 +{ 1.87 + int have_vmx = FALSE; 1.88 + int fd; 1.89 + struct 1.90 + { 1.91 + unsigned long type; 1.92 + unsigned long value; 1.93 + } aux; 1.94 + 1.95 + fd = open ("/proc/self/auxv", O_RDONLY); 1.96 + if (fd >= 0) 1.97 + { 1.98 + while (read (fd, &aux, sizeof (aux)) == sizeof (aux)) 1.99 + { 1.100 + if (aux.type == AT_HWCAP && (aux.value & PPC_FEATURE_HAS_ALTIVEC)) 1.101 + { 1.102 + have_vmx = TRUE; 1.103 + break; 1.104 + } 1.105 + } 1.106 + 1.107 + close (fd); 1.108 + } 1.109 + 1.110 + return have_vmx; 1.111 +} 1.112 + 1.113 +#else /* !__APPLE__ && !__OpenBSD__ && !__linux__ */ 1.114 +#include <signal.h> 1.115 +#include <setjmp.h> 1.116 + 1.117 +static jmp_buf jump_env; 1.118 + 1.119 +static void 1.120 +vmx_test (int sig, 1.121 + siginfo_t *si, 1.122 + void * unused) 1.123 +{ 1.124 + longjmp (jump_env, 1); 1.125 +} 1.126 + 1.127 +static pixman_bool_t 1.128 +pixman_have_vmx (void) 1.129 +{ 1.130 + struct sigaction sa, osa; 1.131 + int jmp_result; 1.132 + 1.133 + sa.sa_flags = SA_SIGINFO; 1.134 + sigemptyset (&sa.sa_mask); 1.135 + sa.sa_sigaction = vmx_test; 1.136 + sigaction (SIGILL, &sa, &osa); 1.137 + jmp_result = setjmp (jump_env); 1.138 + if (jmp_result == 0) 1.139 + { 1.140 + asm volatile ( "vor 0, 0, 0" ); 1.141 + } 1.142 + sigaction (SIGILL, &osa, NULL); 1.143 + return (jmp_result == 0); 1.144 +} 1.145 + 1.146 +#endif /* __APPLE__ */ 1.147 +#endif /* USE_VMX */ 1.148 + 1.149 +pixman_implementation_t * 1.150 +_pixman_ppc_get_implementations (pixman_implementation_t *imp) 1.151 +{ 1.152 +#ifdef USE_VMX 1.153 + if (!_pixman_disabled ("vmx") && pixman_have_vmx ()) 1.154 + imp = _pixman_implementation_create_vmx (imp); 1.155 +#endif 1.156 + 1.157 + return imp; 1.158 +}