| 1 |
From: Simon McVittie <[email protected]> |
| 2 |
Date: Wed, 4 Oct 2017 08:38:36 +0100 |
| 3 |
Subject: Disable Altivec instructions on PowerPC unless requested |
| 4 |
|
| 5 |
Baseline PowerPC CPUs are not guaranteed to have Altivec instructions |
| 6 |
available, even if they are 64-bit. |
| 7 |
|
| 8 |
Unlike SSE and similar extensions on x86, there does not seem to be |
| 9 |
a way to enable conditional, targeted use of Altivec based on runtime |
| 10 |
detection (which is what ioquake3 wants to do) without also giving the |
| 11 |
compiler permission to use Altivec in code generation; so to not crash |
| 12 |
on the affected CPUs, we'll have to turn it off altogether. |
| 13 |
|
| 14 |
At one point Altivec was an important optimization, because the |
| 15 |
most commonly available PowerPC CPUs (in Apple G4/G5 hardware) |
| 16 |
had the Altivec instructions, and they were a significant benefit |
| 17 |
there. However, Apple haven't sold PowerPC devices for over 10 years, |
| 18 |
some more recently-manufactured PowerPC CPUs like the (64-bit) Freescale |
| 19 |
e5500 omit Altivec, and CPUs in general are a lot faster now than they |
| 20 |
were when the idTech3 engine was first released, hopefully making the |
| 21 |
optimization unnecessary. |
| 22 |
|
| 23 |
This commit uses -mno-altivec to force Altivec instructions not to be |
| 24 |
emitted, unless Altivec is requested via "make USE_ALTIVEC=1". The Apple |
| 25 |
fork of gcc doesn't document the corresponding -fno-altivec option, so |
| 26 |
we'll have to assume that omitting -faltivec is enough (but non-Altivec |
| 27 |
PowerPC Macs haven't been sold for a long time anyway). |
| 28 |
|
| 29 |
Similar to https://github.com/ioquake/ioq3/pull/337 in ioquake3. |
| 30 |
|
| 31 |
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=701630 |
| 32 |
Forwarded: no |
| 33 |
--- |
| 34 |
Makefile | 27 +++++++++++++++++++++++---- |
| 35 |
code/qcommon/q_platform.h | 2 +- |
| 36 |
2 files changed, 24 insertions(+), 5 deletions(-) |
| 37 |
|
| 38 |
diff --git a/Makefile b/Makefile |
| 39 |
index 5454799..a46863f 100644 |
| 40 |
--- a/Makefile |
| 41 |
+++ b/Makefile |
| 42 |
@@ -135,6 +135,10 @@ ifndef USE_LOCAL_HEADERS |
| 43 |
USE_LOCAL_HEADERS=1 |
| 44 |
endif |
| 45 |
|
| 46 |
+ifndef USE_ALTIVEC |
| 47 |
+USE_ALTIVEC=0 |
| 48 |
+endif |
| 49 |
+ |
| 50 |
############################################################################# |
| 51 |
|
| 52 |
BD=$(BUILD_DIR)/debug-$(PLATFORM)-$(ARCH) |
| 53 |
@@ -258,11 +262,19 @@ ifneq (,$(findstring "$(PLATFORM)", "linux" "gnu_kfreebsd" "kfreebsd-gnu" "gnu") |
| 54 |
HAVE_VM_COMPILED=true |
| 55 |
else |
| 56 |
ifeq ($(ARCH),ppc) |
| 57 |
- BASE_CFLAGS += -maltivec |
| 58 |
+ ifeq ($(USE_ALTIVEC),1) |
| 59 |
+ BASE_CFLAGS += -maltivec -DUSE_ALTIVEC |
| 60 |
+ else |
| 61 |
+ BASE_CFLAGS += -mno-altivec |
| 62 |
+ endif |
| 63 |
HAVE_VM_COMPILED=true |
| 64 |
endif |
| 65 |
ifeq ($(ARCH),ppc64) |
| 66 |
- BASE_CFLAGS += -maltivec |
| 67 |
+ ifeq ($(USE_ALTIVEC),1) |
| 68 |
+ BASE_CFLAGS += -maltivec -DUSE_ALTIVEC |
| 69 |
+ else |
| 70 |
+ BASE_CFLAGS += -mno-altivec |
| 71 |
+ endif |
| 72 |
HAVE_VM_COMPILED=true |
| 73 |
endif |
| 74 |
ifeq ($(ARCH),sparc) |
| 75 |
@@ -335,11 +347,18 @@ ifeq ($(PLATFORM),darwin) |
| 76 |
BASE_CFLAGS = -Wall -Wimplicit -Wstrict-prototypes |
| 77 |
|
| 78 |
ifeq ($(ARCH),ppc) |
| 79 |
- BASE_CFLAGS += -faltivec |
| 80 |
+ ifeq ($(USE_ALTIVEC),1) |
| 81 |
+ # -fno-altivec doesn't seem to exist according to |
| 82 |
+ # http://www.manpages.info/macosx/gcc.1.html so we'll just have to |
| 83 |
+ # hope that the default is no Altivec |
| 84 |
+ BASE_CFLAGS += -faltivec -DUSE_ALTIVEC |
| 85 |
+ endif |
| 86 |
OPTIMIZE += -O3 |
| 87 |
endif |
| 88 |
ifeq ($(ARCH),ppc64) |
| 89 |
- BASE_CFLAGS += -faltivec |
| 90 |
+ ifeq ($(USE_ALTIVEC),1) |
| 91 |
+ BASE_CFLAGS += -faltivec -DUSE_ALTIVEC |
| 92 |
+ endif |
| 93 |
endif |
| 94 |
ifeq ($(ARCH),i386) |
| 95 |
OPTIMIZE += -march=prescott -mfpmath=sse |
| 96 |
diff --git a/code/qcommon/q_platform.h b/code/qcommon/q_platform.h |
| 97 |
index fc8d40d..3e3f3b5 100644 |
| 98 |
--- a/code/qcommon/q_platform.h |
| 99 |
+++ b/code/qcommon/q_platform.h |
| 100 |
@@ -41,7 +41,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 101 |
#if (defined(powerc) || defined(powerpc) || defined(ppc) || \ |
| 102 |
defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY) |
| 103 |
#define idppc 1 |
| 104 |
-#if defined(__VEC__) |
| 105 |
+#if defined(__VEC__) && defined(USE_ALTIVEC) |
| 106 |
#define idppc_altivec 1 |
| 107 |
#ifdef MACOS_X // Apple's GCC does this differently than the FSF. |
| 108 |
#define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ |