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"
30 /* The CPU detection code needs to be in a file not compiled with
31 * "-maltivec -mabi=altivec", as gcc would try to save vector register
32 * across function calls causing SIGILL on cpus without Altivec/vmx.
35 #include <sys/sysctl.h>
38 pixman_have_vmx (void)
41 size_t length
= sizeof(have_vmx
);
43 error
= sysctlbyname ("hw.optional.altivec", &have_vmx
, &length
, NULL
, 0);
51 #elif defined (__OpenBSD__)
52 #include <sys/param.h>
53 #include <sys/sysctl.h>
54 #include <machine/cpu.h>
57 pixman_have_vmx (void)
60 int mib
[2] = { CTL_MACHDEP
, CPU_ALTIVEC
};
61 size_t length
= sizeof(have_vmx
);
63 error
= sysctl (mib
, 2, &have_vmx
, &length
, NULL
, 0);
71 #elif defined (__linux__)
73 #include <sys/types.h>
78 #include <linux/auxvec.h>
79 #include <asm/cputable.h>
82 pixman_have_vmx (void)
92 fd
= open ("/proc/self/auxv", O_RDONLY
);
95 while (read (fd
, &aux
, sizeof (aux
)) == sizeof (aux
))
97 if (aux
.type
== AT_HWCAP
&& (aux
.value
& PPC_FEATURE_HAS_ALTIVEC
))
110 #else /* !__APPLE__ && !__OpenBSD__ && !__linux__ */
114 static jmp_buf jump_env
;
121 longjmp (jump_env
, 1);
125 pixman_have_vmx (void)
127 struct sigaction sa
, osa
;
130 sa
.sa_flags
= SA_SIGINFO
;
131 sigemptyset (&sa
.sa_mask
);
132 sa
.sa_sigaction
= vmx_test
;
133 sigaction (SIGILL
, &sa
, &osa
);
134 jmp_result
= setjmp (jump_env
);
137 asm volatile ( "vor 0, 0, 0" );
139 sigaction (SIGILL
, &osa
, NULL
);
140 return (jmp_result
== 0);
143 #endif /* __APPLE__ */
146 pixman_implementation_t
*
147 _pixman_ppc_get_implementations (pixman_implementation_t
*imp
)
150 if (!_pixman_disabled ("vmx") && pixman_have_vmx ())
151 imp
= _pixman_implementation_create_vmx (imp
);