Friday, May 01, 2020

[macppc, !x86] Unbreak emulators/gsplus

Hi,

> http://build-failures.rhaalovely.net/powerpc/2020-04-09/emulators/gsplus.log

`__builtin_ppc_mftb()' is not available with clang.

An easy solution would have been to change the ifdef, but as this is
the same situation with retroarch [0], i preferred to use their logic.
On top of that it should slightly improve the emulation on !{x86,ppc}.

I don't know why upstream chose to #define a builtin, so it can't be
applied on archs where it is native (x86). The intent of this patch is
to be upstreamed so i preferred to stay minimal.

This allows gsplus to be built on macppc, i can run System 6 without
issues, excepted mouse clicks that don't register. The only other arch
i have is amd64, where this diff makes no change.

Comments/feedback are welcome,

Charlène.


[0] https://marc.info/?l=openbsd-ports-cvs&m=158816954508000&w=2


Index: Makefile
===================================================================
RCS file: /cvs/ports/emulators/gsplus/Makefile,v
retrieving revision 1.1.1.1
diff -u -p -u -p -r1.1.1.1 Makefile
--- Makefile 12 Mar 2020 12:24:08 -0000 1.1.1.1
+++ Makefile 1 May 2020 21:36:37 -0000
@@ -6,6 +6,7 @@ GH_ACCOUNT = digarok
GH_PROJECT = gsplus
GH_COMMIT = 480572054518112647c8fae5d7ea7046a6d6ecfb
DISTNAME = ${GH_PROJECT}-20190816
+REVISION = 0

CATEGORIES = emulators

Index: patches/patch-src_engine_c_c
===================================================================
RCS file: patches/patch-src_engine_c_c
diff -N patches/patch-src_engine_c_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_engine_c_c 1 May 2020 21:36:37 -0000
@@ -0,0 +1,24 @@
+$OpenBSD$
+
+Use posix timing to improve portability and avoid a build failure on
+powerpc due to `__builtin_ppc_mftb' being gcc-specific.
+
+Index: src/engine_c.c
+--- src/engine_c.c.orig
++++ src/engine_c.c
+@@ -884,6 +884,15 @@ void fixed_memory_ptrs_shut() {
+
+ #if defined(__i386__) || defined(__x86_64__)
+ #include <x86intrin.h>
++ #elif defined(_POSIX_MONOTONIC_CLOCK)
++ #include <time.h>
++ int64_t __rdtsc() {
++ struct timespec tp = {0};
++ int64_t timestamp = 0;
++ if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
++ timestamp = tp.tv_sec * 1000000000 + tp.tv_nsec;
++ return timestamp;
++ }
+ #elif defined(__powerpc__) || defined(__ppc__)
+ #define __rdtsc() __builtin_ppc_mftb()
+ #else

No comments:

Post a Comment