mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
merged patches from Chris Csanady and John Steele Scott, better checking for altivec and ppc64 on ppc
This commit is contained in:
@@ -29,10 +29,21 @@
|
|||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
lib_LTLIBRARIES = libFLAC.la
|
lib_LTLIBRARIES = libFLAC.la
|
||||||
|
DEBUGCFLAGS =
|
||||||
|
CPUCFLAGS =
|
||||||
if DEBUG
|
if DEBUG
|
||||||
DEBUGCFLAGS = -DFLAC__OVERFLOW_DETECT
|
DEBUGCFLAGS = -DFLAC__OVERFLOW_DETECT
|
||||||
endif
|
endif
|
||||||
CFLAGS = @CFLAGS@ $(DEBUGCFLAGS)
|
if FLaC__CPU_PPC
|
||||||
|
# The -force_cpusubtype_ALL is needed to insert a ppc64 instruction
|
||||||
|
# into cpu.c with an asm().
|
||||||
|
if FLaC__SYS_DARWIN
|
||||||
|
CPUCFLAGS= -faltivec -force_cpusubtype_ALL
|
||||||
|
else
|
||||||
|
CPUCFLAGS= -maltivec -mabi=altivec -force_cpusubtype_ALL
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
CFLAGS = @CFLAGS@ $(DEBUGCFLAGS) $(CPUCFLAGS)
|
||||||
|
|
||||||
if FLaC__NO_ASM
|
if FLaC__NO_ASM
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -30,8 +30,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "private/cpu.h"
|
#include "private/cpu.h"
|
||||||
#include<stdlib.h>
|
#include <stdlib.h>
|
||||||
#include<stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
@@ -39,9 +39,32 @@
|
|||||||
|
|
||||||
#if defined FLAC__CPU_PPC
|
#if defined FLAC__CPU_PPC
|
||||||
#if !defined FLAC__NO_ASM
|
#if !defined FLAC__NO_ASM
|
||||||
#if defined __APPLE__ && defined __MACH__
|
#if defined FLAC__SYS_DARWIN
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif /* __APPLE__ && __MACH__ */
|
#include <mach/mach.h>
|
||||||
|
#include <mach/mach_host.h>
|
||||||
|
#include <mach/host_info.h>
|
||||||
|
#include <mach/machine.h>
|
||||||
|
#ifndef CPU_SUBTYPE_POWERPC_970
|
||||||
|
#define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
|
||||||
|
#endif
|
||||||
|
#else /* FLAC__SYS_DARWIN */
|
||||||
|
#include <signal.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
static sigjmp_buf jmpbuf;
|
||||||
|
static volatile sig_atomic_t canjump = 0;
|
||||||
|
|
||||||
|
static void sigill_handler (int sig)
|
||||||
|
{
|
||||||
|
if (!canjump) {
|
||||||
|
signal (sig, SIG_DFL);
|
||||||
|
raise (sig);
|
||||||
|
}
|
||||||
|
canjump = 0;
|
||||||
|
siglongjmp (jmpbuf, 1);
|
||||||
|
}
|
||||||
|
#endif /* FLAC__SYS_DARWIN */
|
||||||
#endif /* FLAC__NO_ASM */
|
#endif /* FLAC__NO_ASM */
|
||||||
#endif /* FLAC__CPU_PPC */
|
#endif /* FLAC__CPU_PPC */
|
||||||
|
|
||||||
@@ -91,7 +114,7 @@ void FLAC__cpu_info(FLAC__CPUInfo *info)
|
|||||||
#if !defined FLAC__NO_ASM
|
#if !defined FLAC__NO_ASM
|
||||||
info->use_asm = true;
|
info->use_asm = true;
|
||||||
#ifdef FLAC__USE_ALTIVEC
|
#ifdef FLAC__USE_ALTIVEC
|
||||||
#if defined __APPLE__ && defined __MACH__
|
#if defined FLAC__SYS_DARWIN
|
||||||
{
|
{
|
||||||
int selectors[2] = { CTL_HW, HW_VECTORUNIT };
|
int selectors[2] = { CTL_HW, HW_VECTORUNIT };
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@@ -100,12 +123,51 @@ void FLAC__cpu_info(FLAC__CPUInfo *info)
|
|||||||
|
|
||||||
info->data.ppc.altivec = error==0 ? result!=0 : 0;
|
info->data.ppc.altivec = error==0 ? result!=0 : 0;
|
||||||
}
|
}
|
||||||
#else /* __APPLE__ && __MACH__ */
|
{
|
||||||
/* don't know of any other thread-safe way to check */
|
host_basic_info_data_t hostInfo;
|
||||||
info->data.ppc.altivec = 0;
|
mach_msg_type_number_t infoCount;
|
||||||
#endif /* __APPLE__ && __MACH__ */
|
|
||||||
|
infoCount = HOST_BASIC_INFO_COUNT;
|
||||||
|
host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
|
||||||
|
|
||||||
|
info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
|
||||||
|
}
|
||||||
|
#else /* FLAC__SYS_DARWIN */
|
||||||
|
{
|
||||||
|
/* no Darwin, do it the brute-force way */
|
||||||
|
/* this is borrowed from MPlayer from the libmpeg2 library */
|
||||||
|
info->data.ppc.altivec = 0;
|
||||||
|
info->data.ppc.ppc64 = 0;
|
||||||
|
|
||||||
|
signal (SIGILL, sigill_handler);
|
||||||
|
if (!sigsetjmp (jmpbuf, 1)) {
|
||||||
|
canjump = 1;
|
||||||
|
|
||||||
|
asm volatile (
|
||||||
|
"mtspr 256, %0\n\t"
|
||||||
|
"vand %%v0, %%v0, %%v0"
|
||||||
|
:
|
||||||
|
: "r" (-1)
|
||||||
|
);
|
||||||
|
|
||||||
|
info->data.ppc.altivec = 1;
|
||||||
|
}
|
||||||
|
canjump = 0;
|
||||||
|
if (!sigsetjmp (jmpbuf, 1)) {
|
||||||
|
int x = 0;
|
||||||
|
canjump = 1;
|
||||||
|
|
||||||
|
/* PPC64 hardware implements the cntlzd instruction */
|
||||||
|
asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
|
||||||
|
|
||||||
|
info->data.ppc.ppc64 = 1;
|
||||||
|
}
|
||||||
|
signal (SIGILL, SIG_DFL);
|
||||||
|
}
|
||||||
|
#endif /* FLAC__SYS_DARWIN */
|
||||||
#else /* FLAC__USE_ALTIVEC */
|
#else /* FLAC__USE_ALTIVEC */
|
||||||
info->data.ppc.altivec = 0;
|
info->data.ppc.altivec = 0;
|
||||||
|
info->data.ppc.ppc64 = 0;
|
||||||
#endif /* FLAC__USE_ALTIVEC */
|
#endif /* FLAC__USE_ALTIVEC */
|
||||||
#else /* FLAC__NO_ASM */
|
#else /* FLAC__NO_ASM */
|
||||||
info->use_asm = false;
|
info->use_asm = false;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FLAC__bool altivec;
|
FLAC__bool altivec;
|
||||||
|
FLAC__bool ppc64;
|
||||||
} FLAC__CPUInfo_PPC;
|
} FLAC__CPUInfo_PPC;
|
||||||
|
|
||||||
extern const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV;
|
extern const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV;
|
||||||
|
|||||||
Reference in New Issue
Block a user