[Liboil-commit] 2 commits - liboil/liboilcpu-powerpc.c liboil/ref
David Schleef
ds at kemper.freedesktop.org
Thu Mar 13 01:18:00 PDT 2008
liboil/liboilcpu-powerpc.c | 79 +++++++++++++++++++++++++++++++++++------
liboil/ref/diffsquaresum_f32.c | 4 +-
2 files changed, 70 insertions(+), 13 deletions(-)
New commits:
commit 376aefd191297aeabee92196aa2886f73a974f93
Author: David Schleef <ds at ginger.bigkitten.com>
Date: Thu Mar 13 01:19:54 2008 -0700
Fix broken reference implementation. It couldn't have ever possibly worked, so I don't care if this breaks ABI
diff --git a/liboil/ref/diffsquaresum_f32.c b/liboil/ref/diffsquaresum_f32.c
index 392fa14..13d8a1e 100644
--- a/liboil/ref/diffsquaresum_f32.c
+++ b/liboil/ref/diffsquaresum_f32.c
@@ -59,8 +59,8 @@ diffsquaresum_f32_ref(float *dest, float *src1, int sstr1, float *src2,
int i;
for(i=0;i<n;i++){
- x = OIL_GET(src1, i*sstr1, double) -
- OIL_GET(src2, i*sstr2, double);
+ x = OIL_GET(src1, i*sstr1, float) -
+ OIL_GET(src2, i*sstr2, float);
x = x*x;
tmp = sum;
sum += x;
commit df0e54862b788e44e4bc21fab4c10032be664056
Author: David Schleef <ds at ginger.bigkitten.com>
Date: Thu Mar 13 00:23:21 2008 -0700
Use /proc/self/auxv to test for altivec on Linux. Patch from #14914
diff --git a/liboil/liboilcpu-powerpc.c b/liboil/liboilcpu-powerpc.c
index a0f029f..6ae591b 100644
--- a/liboil/liboilcpu-powerpc.c
+++ b/liboil/liboilcpu-powerpc.c
@@ -34,15 +34,20 @@
#include <liboil/liboilfault.h>
#include <liboil/liboilutils.h>
-//#include <unistd.h>
-//#include <fcntl.h>
-//#include <stdlib.h>
-//#include <string.h>
-//#include <stdio.h>
-//#include <setjmp.h>
-//#include <signal.h>
-//#include <sys/time.h>
-//#include <time.h>
+#if defined(__linux__)
+#include <linux/auxvec.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#ifndef PPC_FEATURE_HAS_ALTIVEC
+/* From linux-2.6/include/asm-powerpc/cputable.h */
+#define PPC_FEATURE_HAS_ALTIVEC 0x10000000
+#endif
+
+#endif
#if defined(__FreeBSD__)
#include <sys/types.h>
@@ -67,7 +72,7 @@ test_altivec (void * ignored)
}
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-void
+static void
oil_check_altivec_sysctl_freebsd (void)
{
int ret, av;
@@ -82,7 +87,7 @@ oil_check_altivec_sysctl_freebsd (void)
#endif
#if defined(__APPLE__)
-void
+static void
oil_check_altivec_sysctl_darwin (void)
{
int ret, vu;
@@ -96,6 +101,56 @@ oil_check_altivec_sysctl_darwin (void)
}
#endif
+#if defined(__linux__)
+static void
+oil_check_altivec_proc_auxv (void)
+{
+ static int available = -1;
+ int new_avail = 0;
+ unsigned long buf[64];
+ ssize_t count;
+ int fd, i;
+
+ /* Flags already set */
+ if (available != -1) {
+ return;
+ }
+
+ fd = open("/proc/self/auxv", O_RDONLY);
+ if (fd < 0) {
+ goto out;
+ }
+
+more:
+ count = read(fd, buf, sizeof(buf));
+ if (count < 0) {
+ goto out_close;
+ }
+
+ for (i=0; i < (count / sizeof(unsigned long)); i += 2) {
+ if (buf[i] == AT_HWCAP) {
+ new_avail = !!(buf[i+1] & PPC_FEATURE_HAS_ALTIVEC);
+ goto out_close;
+ } else if (buf[i] == AT_NULL) {
+ goto out_close;
+ }
+ }
+
+ if (count == sizeof(buf)) {
+ goto more;
+ }
+
+out_close:
+ close(fd);
+
+out:
+ available = new_avail;
+ if (available) {
+ oil_cpu_flags |= OIL_IMPL_FLAG_ALTIVEC;
+ }
+}
+#endif
+
void
oil_check_altivec_fault (void)
{
@@ -114,6 +169,8 @@ oil_cpu_detect_arch(void)
oil_check_altivec_sysctl_freebsd();
#elif defined(__APPLE__)
oil_check_altivec_sysctl_darwin();
+#elif defined(__linux__)
+ oil_check_altivec_proc_auxv();
#else
oil_check_altivec_fault();
#endif
More information about the Liboil-commit
mailing list