Skip to content

Commit

Permalink
PowerPC: Detect AltiVec support on OS X
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dwatteau authored and dcommander committed Jul 7, 2022
1 parent 604ba92 commit d258375
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -10,7 +10,7 @@ if(CMAKE_EXECUTABLE_SUFFIX)
endif()

project(libjpeg-turbo C)
set(VERSION 2.0.7)
set(VERSION 2.0.8)
set(COPYRIGHT_YEAR "1991-2022")
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
Expand Down
11 changes: 11 additions & 0 deletions ChangeLog.md
@@ -1,3 +1,14 @@
2.0.8 ESR
=========

### Significant changes relative to 2.0.7 ESR:

1. 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.0.7 ESR
=========

Expand Down
13 changes: 10 additions & 3 deletions simd/powerpc/jsimd.c
Expand Up @@ -31,7 +31,10 @@
#include <string.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/sysctl.h>
#include <machine/cpu.h>
Expand Down Expand Up @@ -121,6 +124,10 @@ init_simd(void)
int bufsize = 1024; /* an initial guess for the line buffer size limit */
#elif defined(__amigaos4__)
uint32 altivec = 0;
#elif defined(__APPLE__)
int mib[2] = { CTL_HW, HW_VECTORUNIT };
int altivec;
size_t len = sizeof(altivec);
#elif defined(__OpenBSD__)
int mib[2] = { CTL_MACHDEP, CPU_ALTIVEC };
int altivec;
Expand All @@ -134,7 +141,7 @@ init_simd(void)

simd_support = 0;

#if defined(__ALTIVEC__) || defined(__APPLE__)
#if defined(__ALTIVEC__)
simd_support |= JSIMD_ALTIVEC;
#elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
while (!parse_proc_cpuinfo(bufsize)) {
Expand All @@ -146,7 +153,7 @@ init_simd(void)
IExec->GetCPUInfoTags(GCIT_VectorUnit, &altivec, TAG_DONE);
if (altivec == VECTORTYPE_ALTIVEC)
simd_support |= JSIMD_ALTIVEC;
#elif defined(__OpenBSD__)
#elif defined(__APPLE__) || defined(__OpenBSD__)
if (sysctl(mib, 2, &altivec, &len, NULL, 0) == 0 && altivec != 0)
simd_support |= JSIMD_ALTIVEC;
#elif defined(__FreeBSD__)
Expand Down

0 comments on commit d258375

Please sign in to comment.