summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorSergey Fedorov <vital.had@gmail.com>2022-10-19 18:49:45 +0800
committerGitHub <noreply@github.com>2022-10-19 23:49:45 +1300
commit567725ed303b6738493c80efaf93dc4c1e65a9c9 (patch)
tree75f141047050eee63c05d613491595a7a9380afa /gc.c
parentfc3137ef54562c3c3290245c0f62e0bb193c3145 (diff)
Fix and improve coroutines for Darwin (macOS) ppc/ppc64. (#5975)
Notes
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/gc.c b/gc.c
index 7373bcfd67..ffc610dcc7 100644
--- a/gc.c
+++ b/gc.c
@@ -1359,6 +1359,27 @@ tick(void)
return val;
}
+/* Implementation for macOS PPC by @nobu
+ * See: https://github.com/ruby/ruby/pull/5975#discussion_r890045558
+ */
+#elif defined(__POWERPC__) && defined(__APPLE__)
+typedef unsigned long long tick_t;
+#define PRItick "llu"
+
+static __inline__ tick_t
+tick(void)
+{
+ unsigned long int upper, lower, tmp;
+ # define mftbu(r) __asm__ volatile("mftbu %0" : "=r"(r))
+ # define mftb(r) __asm__ volatile("mftb %0" : "=r"(r))
+ do {
+ mftbu(upper);
+ mftb(lower);
+ mftbu(tmp);
+ } while (tmp != upper);
+ return ((tick_t)upper << 32) | lower;
+}
+
#elif defined(__aarch64__) && defined(__GNUC__)
typedef unsigned long tick_t;
#define PRItick "lu"