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

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