Skip to content

Commit 76c8a4c

Browse files
committed
unix: Add setjmp-based GC register helper implementation.
As I suspected for a long time, for x86, register helper doesn't really make any difference - there's simply not enough register to keep anything in them for any prolonged time. Anything gets pushed on stack anyway. So, on x86, uPy passed all tests even with empty reg helper. So, this setjmp implementation goes as "untested".
1 parent 30583f5 commit 76c8a4c

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

unix/gccollect.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@
3434

3535
extern void *stack_top;
3636

37+
#if MICROPY_GCREGS_SETJMP
38+
#include <setjmp.h>
39+
40+
typedef jmp_buf regs_t;
41+
42+
void gc_helper_get_regs(regs_t arr) {
43+
setjmp(arr);
44+
}
45+
46+
#else // !MICROPY_GCREGS_SETJMP
47+
3748
// We capture here callee-save registers, i.e. ones which may contain
3849
// interesting values held there by our callers. It doesn't make sense
3950
// to capture caller-saved registers, because they, well, put on the
@@ -112,6 +123,7 @@ void gc_helper_get_regs(regs_t arr) {
112123
arr[9] = r13;
113124
}
114125
#endif
126+
#endif // !MICROPY_GCREGS_SETJMP
115127

116128
void gc_collect(void) {
117129
//gc_dump_info();

unix/mpconfigport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
// Define to MICROPY_ERROR_REPORTING_DETAILED to get function, etc.
5050
// names in exception messages (may require more RAM).
5151
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
52+
// Define to 1 to use untested inefficient GC helper implementation
53+
// (if more efficient arch-specific one is not available).
54+
#define MICROPY_GCREGS_SETJMP (0)
5255

5356
extern const struct _mp_obj_module_t mp_module_os;
5457
extern const struct _mp_obj_module_t mp_module_time;

0 commit comments

Comments
 (0)