Skip to content

Commit 6e68a68

Browse files
committed
unix/gccollect: Fallback to setjmp-based register fetching automatically.
Now, if we build for an architecture which doesn't have dedicated support for getting registers for GC scanning, fallback to setjmp-based method automatically. It's still possible to force setjmp-based implementation on archs with dedicated support (e.g. for testing, or for peculiar calling conventions/optimizations).
1 parent 57e00ef commit 6e68a68

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

unix/gccollect.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,15 @@
3131

3232
#if MICROPY_ENABLE_GC
3333

34-
#if MICROPY_GCREGS_SETJMP
35-
#include <setjmp.h>
36-
37-
typedef jmp_buf regs_t;
38-
39-
STATIC void gc_helper_get_regs(regs_t arr) {
40-
setjmp(arr);
41-
}
42-
43-
#else // !MICROPY_GCREGS_SETJMP
34+
// Even if we have specific support for an architecture, it is
35+
// possible to force use of setjmp-based implementation.
36+
#if !MICROPY_GCREGS_SETJMP
4437

4538
// We capture here callee-save registers, i.e. ones which may contain
4639
// interesting values held there by our callers. It doesn't make sense
4740
// to capture caller-saved registers, because they, well, put on the
4841
// stack already by the caller.
49-
#ifdef __x86_64__
42+
#if defined(__x86_64__)
5043
typedef mp_uint_t regs_t[6];
5144

5245
STATIC void gc_helper_get_regs(regs_t arr) {
@@ -77,9 +70,9 @@ STATIC void gc_helper_get_regs(regs_t arr) {
7770
arr[4] = r14;
7871
arr[5] = r15;
7972
}
80-
#endif
8173

82-
#ifdef __i386__
74+
#elif defined(__i386__)
75+
8376
typedef mp_uint_t regs_t[4];
8477

8578
STATIC void gc_helper_get_regs(regs_t arr) {
@@ -92,9 +85,9 @@ STATIC void gc_helper_get_regs(regs_t arr) {
9285
arr[2] = edi;
9386
arr[3] = ebp;
9487
}
95-
#endif
9688

97-
#if defined(__thumb2__) || defined(__thumb__) || defined(__arm__)
89+
#elif defined(__thumb2__) || defined(__thumb__) || defined(__arm__)
90+
9891
typedef mp_uint_t regs_t[10];
9992

10093
STATIC void gc_helper_get_regs(regs_t arr) {
@@ -119,9 +112,30 @@ STATIC void gc_helper_get_regs(regs_t arr) {
119112
arr[8] = r12;
120113
arr[9] = r13;
121114
}
122-
#endif
115+
116+
#else
117+
118+
// If we don't have architecture-specific optimized support,
119+
// just fall back to setjmp-based implementation.
120+
#undef MICROPY_GCREGS_SETJMP
121+
#define MICROPY_GCREGS_SETJMP (1)
122+
123+
#endif // Arch-specific selection
123124
#endif // !MICROPY_GCREGS_SETJMP
124125

126+
// If MICROPY_GCREGS_SETJMP was requested explicitly, or if
127+
// we enabled it as a fallback above.
128+
#if MICROPY_GCREGS_SETJMP
129+
#include <setjmp.h>
130+
131+
typedef jmp_buf regs_t;
132+
133+
STATIC void gc_helper_get_regs(regs_t arr) {
134+
setjmp(arr);
135+
}
136+
137+
#endif // MICROPY_GCREGS_SETJMP
138+
125139
void gc_collect(void) {
126140
//gc_dump_info();
127141

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy