mpg123: build: maybe having handled Android with global ptrs now (bug 345)

From 5475987f8fb303daf692f3167f5e81506e3c0dcf Mon Sep 17 00:00:00 2001
From: thor <[EMAIL REDACTED]>
Date: Thu, 13 Oct 2022 21:51:47 +0000
Subject: [PATCH] build: maybe having handled Android with global ptrs now (bug
 345)

git-svn-id: svn://scm.orgis.org/mpg123/trunk@5173 35dc7657-300d-0410-a2e5-dc2837fedb53
---
 src/libmpg123/dct36_3dnow.S     | 24 +++++++++++++-----------
 src/libmpg123/dct36_3dnowext.S  | 24 +++++++++++++-----------
 src/libmpg123/dct64_3dnow.S     | 10 +++++-----
 src/libmpg123/dct64_mmx.S       |  2 +-
 src/libmpg123/dct64_sse.S       |  2 +-
 src/libmpg123/dct64_sse_float.S |  2 +-
 src/libmpg123/mangle.h          |  5 +++++
 7 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/src/libmpg123/dct36_3dnow.S b/src/libmpg123/dct36_3dnow.S
index 2d45dc0..9b0222d 100644
--- a/src/libmpg123/dct36_3dnow.S
+++ b/src/libmpg123/dct36_3dnow.S
@@ -35,7 +35,9 @@
 ASM_NAME(dct36_3dnow):
 	pushl %ebp
 	movl %esp,%ebp
-#if defined(PIC) && defined(__APPLE__)
+// Not entirely sure about this PIC_GLOBAL_PTR here, but this is highly
+// irrelevant, anyway. Anyone building 3DNow code for Android or Apple systems?
+#ifdef PIC_GLOBAL_PTR
 	sub $4,%esp
 #endif
 	pushl %esi
@@ -45,7 +47,7 @@ ASM_NAME(dct36_3dnow):
 	#define _EBX_ %edi
 	PREPARE_GOT
 	GET_GOT
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	#define _COS9_ 0(%edi)
 	#define _tfcos36_ 0(%eax)
 	mov GLOBAL_VAR_PTR(tfcos36), %eax
@@ -187,7 +189,7 @@ ASM_NAME(dct36_3dnow):
 	movq %mm2,%mm4
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 0+_tfcos36_,%mm5
@@ -217,7 +219,7 @@ ASM_NAME(dct36_3dnow):
 	pfsub %mm2,%mm4
 	movq %mm7,%mm5
 	punpckldq 32+_tfcos36_,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov 8(%ebp),%eax
 #endif
 	pfmul %mm5,%mm4
@@ -265,7 +267,7 @@ ASM_NAME(dct36_3dnow):
 	movq %mm2,%mm4
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 4+_tfcos36_,%mm5
@@ -295,7 +297,7 @@ ASM_NAME(dct36_3dnow):
 	pfsub %mm2,%mm4
 	movq %mm7,%mm5
 	punpckldq 28+_tfcos36_,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov 8(%ebp),%eax
 #endif
 	pfmul %mm5,%mm4
@@ -356,7 +358,7 @@ ASM_NAME(dct36_3dnow):
 	movq %mm2,%mm4
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 8+_tfcos36_,%mm5
@@ -386,7 +388,7 @@ ASM_NAME(dct36_3dnow):
 	pfsub %mm2,%mm4
 	movq %mm7,%mm5
 	punpckldq 24+_tfcos36_,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov 8(%ebp),%eax
 #endif
 	pfmul %mm5,%mm4
@@ -446,7 +448,7 @@ ASM_NAME(dct36_3dnow):
 	movq %mm2,%mm4
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 12+_tfcos36_,%mm5
@@ -476,7 +478,7 @@ ASM_NAME(dct36_3dnow):
 	pfsub %mm2,%mm4
 	movq %mm7,%mm5
 	punpckldq 20+_tfcos36_,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov 8(%ebp),%eax
 #endif
 	pfmul %mm5,%mm4
@@ -512,7 +514,7 @@ ASM_NAME(dct36_3dnow):
 	movq 64(%eax),%mm3
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 16+_tfcos36_,%mm5
diff --git a/src/libmpg123/dct36_3dnowext.S b/src/libmpg123/dct36_3dnowext.S
index 287b6b9..fb95d43 100644
--- a/src/libmpg123/dct36_3dnowext.S
+++ b/src/libmpg123/dct36_3dnowext.S
@@ -48,7 +48,9 @@
 ASM_NAME(dct36_3dnowext):
 	pushl	%ebp
 	movl	%esp, %ebp
-#if defined(PIC) && defined(__APPLE__)
+// Not entirely sure about this PIC_GLOBAL_PTR here, but this is highly
+// irrelevant, anyway. Anyone building 3DNow code for Android or Apple systems?
+#ifdef PIC_GLOBAL_PTR
 	sub		$4, %esp
 #endif
 	pushl	%esi
@@ -58,7 +60,7 @@ ASM_NAME(dct36_3dnowext):
 	#define _EBX_ %edi
 	PREPARE_GOT
 	GET_GOT
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	#define _COS9_ 0(%edi)
 	#define _tfcos36_ 0(%eax)
 	mov GLOBAL_VAR_PTR(tfcos36), %eax
@@ -198,7 +200,7 @@ ASM_NAME(dct36_3dnowext):
 	movq %mm2,%mm4
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 0+_tfcos36_,%mm5
@@ -227,7 +229,7 @@ ASM_NAME(dct36_3dnowext):
 	pfsub %mm2,%mm4
 	movq %mm7,%mm5
 	punpckldq 32+_tfcos36_,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov 8(%ebp),%eax
 #endif
 	pfmul %mm5,%mm4
@@ -275,7 +277,7 @@ ASM_NAME(dct36_3dnowext):
 	movq %mm2,%mm4
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 4+_tfcos36_,%mm5
@@ -305,7 +307,7 @@ ASM_NAME(dct36_3dnowext):
 	pfsub %mm2,%mm4
 	movq %mm7,%mm5
 	punpckldq 28+_tfcos36_,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov 8(%ebp),%eax
 #endif
 	pfmul %mm5,%mm4
@@ -365,7 +367,7 @@ ASM_NAME(dct36_3dnowext):
 	movq %mm2,%mm4
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 8+_tfcos36_,%mm5
@@ -395,7 +397,7 @@ ASM_NAME(dct36_3dnowext):
 	pfsub %mm2,%mm4
 	movq %mm7,%mm5
 	punpckldq 24+_tfcos36_,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov 8(%ebp),%eax
 #endif
 	pfmul %mm5,%mm4
@@ -455,7 +457,7 @@ ASM_NAME(dct36_3dnowext):
 	movq %mm2,%mm4
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 12+_tfcos36_,%mm5
@@ -485,7 +487,7 @@ ASM_NAME(dct36_3dnowext):
 	pfsub %mm2,%mm4
 	movq %mm7,%mm5
 	punpckldq 20+_tfcos36_,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov 8(%ebp),%eax
 #endif
 	pfmul %mm5,%mm4
@@ -520,7 +522,7 @@ ASM_NAME(dct36_3dnowext):
 	movq 64(%eax),%mm3
 	pfadd %mm3,%mm4
 	movq %mm7,%mm5
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov -4(%ebp),%eax
 #endif
 	punpckldq 16+_tfcos36_,%mm5
diff --git a/src/libmpg123/dct64_3dnow.S b/src/libmpg123/dct64_3dnow.S
index 99e6a2c..5265a87 100644
--- a/src/libmpg123/dct64_3dnow.S
+++ b/src/libmpg123/dct64_3dnow.S
@@ -36,7 +36,7 @@ ASM_NAME(dct64_3dnow):
 	/* femms */
 
 	/* 1 */
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	movl GLOBAL_VAR_PTR(pnts),%eax
 	movl (%eax),%eax
 #else
@@ -140,7 +140,7 @@ ASM_NAME(dct64_3dnow):
 	movd %mm5,64(%ebx)
 	
 	/* 2 */
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	movl GLOBAL_VAR_PTR(pnts),%eax
 	movl 4(%eax),%eax
 #else
@@ -248,7 +248,7 @@ ASM_NAME(dct64_3dnow):
 	movd %mm5,96(%esi)
 
 	/* 3 */
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	movl GLOBAL_VAR_PTR(pnts),%eax
 	movl 8(%eax),%eax
 #else
@@ -354,7 +354,7 @@ ASM_NAME(dct64_3dnow):
 	movd %mm6,112(%ebx)
 	
 	/*  4 */
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	movl GLOBAL_VAR_PTR(pnts),%eax
 	movl 12(%eax),%eax
 #else
@@ -469,7 +469,7 @@ ASM_NAME(dct64_3dnow):
 	pi2fd %mm0,%mm0	
 	movd %eax,%mm1
 	pi2fd %mm1,%mm1
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	movl GLOBAL_VAR_PTR(pnts),%eax
 	movl 16(%eax),%eax
 #else
diff --git a/src/libmpg123/dct64_mmx.S b/src/libmpg123/dct64_mmx.S
index ff8d403..95d426c 100644
--- a/src/libmpg123/dct64_mmx.S
+++ b/src/libmpg123/dct64_mmx.S
@@ -32,7 +32,7 @@ ASM_NAME(dct64_MMX):
 	fstps    (%edx)
 	movl 276(%esp),%edi
 	flds    4(%eax)
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	movl GLOBAL_VAR_PTR(costab_mmxsse),%ebx
 #else
 	leal GLOBAL_VAR(costab_mmxsse),%ebx
diff --git a/src/libmpg123/dct64_sse.S b/src/libmpg123/dct64_sse.S
index 16bcd69..fd1802f 100644
--- a/src/libmpg123/dct64_sse.S
+++ b/src/libmpg123/dct64_sse.S
@@ -77,7 +77,7 @@ ASM_NAME(dct64_sse):
 	subps 		%xmm0, %xmm5
 	subps 		%xmm1, %xmm4
 	
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov			GLOBAL_VAR_PTR(costab_mmxsse), %ecx
 #else
 	lea			GLOBAL_VAR(costab_mmxsse), %ecx
diff --git a/src/libmpg123/dct64_sse_float.S b/src/libmpg123/dct64_sse_float.S
index 544d2d6..1dbd0df 100644
--- a/src/libmpg123/dct64_sse_float.S
+++ b/src/libmpg123/dct64_sse_float.S
@@ -77,7 +77,7 @@ ASM_NAME(dct64_real_sse):
 	subps 		%xmm0, %xmm5
 	subps 		%xmm1, %xmm4
 	
-#if defined(PIC) && defined(__APPLE__)
+#ifdef PIC_GLOBAL_PTR
 	mov			GLOBAL_VAR_PTR(costab_mmxsse), %eax
 #else
 	lea			GLOBAL_VAR(costab_mmxsse), %eax
diff --git a/src/libmpg123/mangle.h b/src/libmpg123/mangle.h
index e37386a..aaebfd3 100644
--- a/src/libmpg123/mangle.h
+++ b/src/libmpg123/mangle.h
@@ -139,6 +139,11 @@ Lpic_base: \
 
 #endif /* PIC variants */
 
+// Apple and Android NDK seem both not to like direct global access.
+#if defined(PIC) && (defined(__APPLE__) || defined(ANDROID))
+#define PIC_GLOBAL_PTR
+#endif
+
 #endif /* OPT_X86 */
 
 #if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__APPLE__)