PowerPC: Detect AltiVec support on OS X

libjpeg-turbo's AltiVec SIMD extensions previously assumed that AltiVec
instructions were available on all Power Macs that supported OS X 10.4
"Tiger" (the earliest version of OS X that libjpeg-turbo has ever
supported), but Tiger can actually run on PowerPC G3 processors, which
lack AltiVec instructions.  This commit enables run-time detection of
AltiVec instructions on OS X/PowerPC systems if AltiVec instructions are
not force-enabled at compile time (using -maltivec).  This allows the
same build of libjpeg-turbo to support G3, G4, and G5 Power Macs.

Closes #609
This commit is contained in:
Donovan Watteau
2022-07-06 12:11:50 +02:00
committed by DRC
parent ba22c0f76d
commit 59337a67b1
2 changed files with 15 additions and 3 deletions

View File

@@ -12,6 +12,11 @@ Visual Studio 2010.
used to prime the decompressor with quantization and Huffman tables that can be used to prime the decompressor with quantization and Huffman tables that can be
used when decompressing subsequent "abbreviated image" datastreams. used when decompressing subsequent "abbreviated image" datastreams.
3. libjpeg-turbo now performs run-time detection of AltiVec instructions on
OS X/PowerPC systems if AltiVec instructions are not enabled at compile time.
This allows both AltiVec-equipped (PowerPC G4 and G5) and non-AltiVec-equipped
(PowerPC G3) CPUs to be supported using the same build of libjpeg-turbo.
2.1.3 2.1.3
===== =====

View File

@@ -29,7 +29,10 @@
#include <ctype.h> #include <ctype.h>
#if defined(__OpenBSD__) #if defined(__APPLE__)
#include <sys/types.h>
#include <sys/sysctl.h>
#elif defined(__OpenBSD__)
#include <sys/param.h> #include <sys/param.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <machine/cpu.h> #include <machine/cpu.h>
@@ -119,6 +122,10 @@ init_simd(void)
int bufsize = 1024; /* an initial guess for the line buffer size limit */ int bufsize = 1024; /* an initial guess for the line buffer size limit */
#elif defined(__amigaos4__) #elif defined(__amigaos4__)
uint32 altivec = 0; uint32 altivec = 0;
#elif defined(__APPLE__)
int mib[2] = { CTL_HW, HW_VECTORUNIT };
int altivec;
size_t len = sizeof(altivec);
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)
int mib[2] = { CTL_MACHDEP, CPU_ALTIVEC }; int mib[2] = { CTL_MACHDEP, CPU_ALTIVEC };
int altivec; int altivec;
@@ -132,7 +139,7 @@ init_simd(void)
simd_support = 0; simd_support = 0;
#if defined(__ALTIVEC__) || defined(__APPLE__) #if defined(__ALTIVEC__)
simd_support |= JSIMD_ALTIVEC; simd_support |= JSIMD_ALTIVEC;
#elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__) #elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
while (!parse_proc_cpuinfo(bufsize)) { while (!parse_proc_cpuinfo(bufsize)) {
@@ -144,7 +151,7 @@ init_simd(void)
IExec->GetCPUInfoTags(GCIT_VectorUnit, &altivec, TAG_DONE); IExec->GetCPUInfoTags(GCIT_VectorUnit, &altivec, TAG_DONE);
if (altivec == VECTORTYPE_ALTIVEC) if (altivec == VECTORTYPE_ALTIVEC)
simd_support |= JSIMD_ALTIVEC; simd_support |= JSIMD_ALTIVEC;
#elif defined(__OpenBSD__) #elif defined(__APPLE__) || defined(__OpenBSD__)
if (sysctl(mib, 2, &altivec, &len, NULL, 0) == 0 && altivec != 0) if (sysctl(mib, 2, &altivec, &len, NULL, 0) == 0 && altivec != 0)
simd_support |= JSIMD_ALTIVEC; simd_support |= JSIMD_ALTIVEC;
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)