Browse Source

nrf/gccollect: Use the SP register instead of MSP.

Using the current stack pointer directly saves 8 bytes of code.
We need the *current* register anyway for GC (which is always MSP).
pull/3137/merge
Ayke van Laethem 7 years ago
committed by Damien George
parent
commit
65f8d9a643
  1. 12
      ports/nrf/gccollect.c

12
ports/nrf/gccollect.c

@ -31,18 +31,18 @@
#include "py/gc.h" #include "py/gc.h"
#include "gccollect.h" #include "gccollect.h"
static inline uint32_t get_msp(void) static inline uintptr_t get_sp(void) {
{ uintptr_t result;
register uint32_t result; __asm__ ("mov %0, sp\n" : "=r" (result) );
__asm volatile ("MRS %0, msp\n" : "=r" (result) ); return result;
return(result);
} }
void gc_collect(void) { void gc_collect(void) {
// start the GC // start the GC
gc_collect_start(); gc_collect_start();
mp_uint_t sp = get_msp(); // Get stack pointer // Get stack pointer
uintptr_t sp = get_sp();
// trace the stack, including the registers (since they live on the stack in this function) // trace the stack, including the registers (since they live on the stack in this function)
gc_collect_root((void**)sp, ((uint32_t)&_ram_end - sp) / sizeof(uint32_t)); gc_collect_root((void**)sp, ((uint32_t)&_ram_end - sp) / sizeof(uint32_t));

Loading…
Cancel
Save