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

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