aboutsummaryrefslogtreecommitdiff
path: root/py/nlrxtensa.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-12-18 18:57:15 +1100
committerDamien George <damien.p.george@gmail.com>2017-12-20 15:42:06 +1100
commit6a3a742a6c9caaa2be0fd0aac7a5df4ac816081c (patch)
treecb91633e1592d474a5bc51db97f6442616d1cf63 /py/nlrxtensa.c
parentd8d633f15658911369d7b1b912777fa74efd3ea6 (diff)
py/nlr: Factor out common NLR code to generic functions.
Each NLR implementation (Thumb, x86, x64, xtensa, setjmp) duplicates a lot of the NLR code, specifically that dealing with pushing and popping the NLR pointer to maintain the linked-list of NLR buffers. This patch factors all of that code out of the specific implementations into generic functions in nlr.c. This eliminates duplicated code. The factoring also allows to make the machine-specific NLR code pure assembler code, thus allowing nlrthumb.c to use naked function attributes in the correct way (naked functions can only have basic inline assembler code in them). There is a small overhead introduced (typically 1 machine instruction) because now the generic nlr_jump() must call nlr_jump_tail() rather than them being one combined function.
Diffstat (limited to 'py/nlrxtensa.c')
-rw-r--r--py/nlrxtensa.c34
1 files changed, 5 insertions, 29 deletions
diff --git a/py/nlrxtensa.c b/py/nlrxtensa.c
index 5a969fc87..6b9918227 100644
--- a/py/nlrxtensa.c
+++ b/py/nlrxtensa.c
@@ -26,7 +26,7 @@
#include "py/mpstate.h"
-#if !MICROPY_NLR_SETJMP && defined(__xtensa__)
+#if MICROPY_NLR_XTENSA
#undef nlr_push
@@ -37,6 +37,7 @@
// a3-a7 = rest of args
unsigned int nlr_push(nlr_buf_t *nlr) {
+ (void)nlr;
__asm volatile (
"s32i.n a0, a2, 8 \n" // save regs...
@@ -55,32 +56,10 @@ unsigned int nlr_push(nlr_buf_t *nlr) {
return 0; // needed to silence compiler warning
}
-__attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr) {
- nlr_buf_t **top = &MP_STATE_THREAD(nlr_top);
- nlr->prev = *top;
- MP_NLR_SAVE_PYSTACK(nlr);
- *top = nlr;
- return 0; // normal return
-}
-
-void nlr_pop(void) {
- nlr_buf_t **top = &MP_STATE_THREAD(nlr_top);
- *top = (*top)->prev;
-}
-
-NORETURN void nlr_jump(void *val) {
- nlr_buf_t **top_ptr = &MP_STATE_THREAD(nlr_top);
- nlr_buf_t *top = *top_ptr;
- if (top == NULL) {
- nlr_jump_fail(val);
- }
-
- top->ret_val = val;
- MP_NLR_RESTORE_PYSTACK(top);
- *top_ptr = top->prev;
+NORETURN void nlr_jump_tail(nlr_buf_t *top) {
+ (void)top;
__asm volatile (
- "mov.n a2, %0 \n" // a2 points to nlr_buf
"l32i.n a0, a2, 8 \n" // restore regs...
"l32i.n a1, a2, 12 \n"
"l32i.n a8, a2, 16 \n"
@@ -93,12 +72,9 @@ NORETURN void nlr_jump(void *val) {
"l32i.n a15, a2, 44 \n"
"movi.n a2, 1 \n" // return 1, non-local return
"ret.n \n" // return
- : // output operands
- : "r"(top) // input operands
- : // clobbered registers
);
for (;;); // needed to silence compiler warning
}
-#endif // !MICROPY_NLR_SETJMP && defined(__xtensa__)
+#endif // MICROPY_NLR_XTENSA