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

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