Blame SOURCES/libvisual-0.4.0-better-altivec-detection.patch

d44b31
--- libvisual-0.4.0/libvisual/lv_cpu.c.orig	2006-01-22 13:23:37.000000000 +0000
d44b31
+++ libvisual-0.4.0/libvisual/lv_cpu.c	2008-03-11 16:00:56.000000000 +0000
d44b31
@@ -50,8 +50,19 @@
d44b31
 #endif
d44b31
 
d44b31
 #if defined(VISUAL_OS_LINUX)
d44b31
+#if defined(VISUAL_ARCH_POWERPC)
d44b31
+#include <sys/types.h>
d44b31
+#include <sys/stat.h>
d44b31
+#include <fcntl.h>
d44b31
+#include <unistd.h>
d44b31
+#include <stdio.h>
d44b31
+
d44b31
+#include <linux/auxvec.h>
d44b31
+#include <asm/cputable.h>
d44b31
+#else /* VISUAL_ARCH_POWERPC */
d44b31
 #include <signal.h>
d44b31
 #endif
d44b31
+#endif
d44b31
 
d44b31
 #if defined(VISUAL_OS_WIN32)
d44b31
 #include <windows.h>
d44b31
@@ -154,6 +165,46 @@ static void check_os_altivec_support( vo
d44b31
 	if (err == 0)
d44b31
 		if (has_vu != 0)
d44b31
 			__lv_cpu_caps.hasAltiVec = 1;
d44b31
+#elif defined (VISUAL_OS_LINUX)
d44b31
+	static int available = -1;
d44b31
+	int new_avail = 0;
d44b31
+	char fname[64];
d44b31
+	unsigned long buf[64];
d44b31
+	ssize_t count;
d44b31
+	pid_t pid;
d44b31
+	int fd, i;
d44b31
+
d44b31
+	if (available != -1)
d44b31
+		return;
d44b31
+
d44b31
+	pid = getpid();
d44b31
+	snprintf(fname, sizeof(fname)-1, "/proc/%d/auxv", pid);
d44b31
+
d44b31
+	fd = open(fname, O_RDONLY);
d44b31
+	if (fd < 0)
d44b31
+		goto out;
d44b31
+more:
d44b31
+	count = read(fd, buf, sizeof(buf));
d44b31
+	if (count < 0)
d44b31
+		goto out_close;
d44b31
+
d44b31
+	for (i=0; i < (count / sizeof(unsigned long)); i += 2) {
d44b31
+		if (buf[i] == AT_HWCAP) {
d44b31
+			new_avail = !!(buf[i+1] & PPC_FEATURE_HAS_ALTIVEC);
d44b31
+			goto out_close;
d44b31
+		} else if (buf[i] == AT_NULL) {
d44b31
+			goto out_close;
d44b31
+		}
d44b31
+	}
d44b31
+
d44b31
+	if (count == sizeof(buf))
d44b31
+		goto more;
d44b31
+out_close:
d44b31
+	close(fd);
d44b31
+out:
d44b31
+	available = new_avail;
d44b31
+	if (available)
d44b31
+		__lv_cpu_caps.hasAltiVec = 1;
d44b31
 #else /* !VISUAL_OS_DARWIN */
d44b31
 	/* no Darwin, do it the brute-force way */
d44b31
 	/* this is borrowed from the libmpeg2 library */