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

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