Skip to content

Commit f140463

Browse files
authored
Merge pull request #2380 from tannewt/gcc9_fixes_from_mp
Incorporate GCC9 fixes from upstream
2 parents 887f64e + 767d47d commit f140463

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

py/mpconfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,15 @@ typedef double mp_float_t;
14401440
#define MP_UNLIKELY(x) __builtin_expect((x), 0)
14411441
#endif
14421442

1443+
// To annotate that code is unreachable
1444+
#ifndef MP_UNREACHABLE
1445+
#if defined(__GNUC__)
1446+
#define MP_UNREACHABLE __builtin_unreachable();
1447+
#else
1448+
#define MP_UNREACHABLE for (;;);
1449+
#endif
1450+
#endif
1451+
14431452
#ifndef MP_HTOBE16
14441453
#if MP_ENDIANNESS_LITTLE
14451454
# define MP_HTOBE16(x) ((uint16_t)( (((x) & 0xff) << 8) | (((x) >> 8) & 0xff) ))

py/nlr.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@
5454
#endif
5555
#elif defined(__thumb2__) || defined(__thumb__) || defined(__arm__)
5656
#define MICROPY_NLR_THUMB (1)
57-
#define MICROPY_NLR_NUM_REGS (10)
57+
#if defined(__SOFTFP__)
58+
#define MICROPY_NLR_NUM_REGS (10)
59+
#else
60+
// With hardware FP registers s16-s31 are callee save so in principle
61+
// should be saved and restored by the NLR code. gcc only uses s16-s21
62+
// so only save/restore those as an optimisation.
63+
#define MICROPY_NLR_NUM_REGS (10 + 6)
64+
#endif
5865
#elif defined(__xtensa__)
5966
#define MICROPY_NLR_XTENSA (1)
6067
#define MICROPY_NLR_NUM_REGS (10)

py/nlrthumb.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ __attribute__((naked)) unsigned int nlr_push(nlr_buf_t *nlr) {
6363
"str r10, [r0, #36] \n" // store r10 into nlr_buf
6464
"str r11, [r0, #40] \n" // store r11 into nlr_buf
6565
"str r13, [r0, #44] \n" // store r13=sp into nlr_buf
66+
#if MICROPY_NLR_NUM_REGS == 16
67+
"vstr d8, [r0, #48] \n" // store s16-s17 into nlr_buf
68+
"vstr d9, [r0, #56] \n" // store s18-s19 into nlr_buf
69+
"vstr d10, [r0, #64] \n" // store s20-s21 into nlr_buf
70+
#endif
6671
"str lr, [r0, #8] \n" // store lr into nlr_buf
6772
#endif
6873

@@ -118,6 +123,11 @@ NORETURN void nlr_jump(void *val) {
118123
"ldr r10, [r0, #36] \n" // load r10 from nlr_buf
119124
"ldr r11, [r0, #40] \n" // load r11 from nlr_buf
120125
"ldr r13, [r0, #44] \n" // load r13=sp from nlr_buf
126+
#if MICROPY_NLR_NUM_REGS == 16
127+
"vldr d8, [r0, #48] \n" // load s16-s17 from nlr_buf
128+
"vldr d9, [r0, #56] \n" // load s18-s19 from nlr_buf
129+
"vldr d10, [r0, #64] \n" // load s20-s21 from nlr_buf
130+
#endif
121131
"ldr lr, [r0, #8] \n" // load lr from nlr_buf
122132
#endif
123133
"movs r0, #1 \n" // return 1, non-local return
@@ -127,11 +137,7 @@ NORETURN void nlr_jump(void *val) {
127137
: // clobbered registers
128138
);
129139

130-
#if defined(__GNUC__)
131-
__builtin_unreachable();
132-
#else
133-
for (;;); // needed to silence compiler warning
134-
#endif
140+
MP_UNREACHABLE
135141
}
136142

137143
#endif // MICROPY_NLR_THUMB

py/nlrx64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ NORETURN void nlr_jump(void *val) {
108108
: // clobbered registers
109109
);
110110

111-
for (;;); // needed to silence compiler warning
111+
MP_UNREACHABLE
112112
}
113113

114114
#endif // MICROPY_NLR_X64

py/nlrx86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ NORETURN void nlr_jump(void *val) {
100100
: // clobbered registers
101101
);
102102

103-
for (;;); // needed to silence compiler warning
103+
MP_UNREACHABLE
104104
}
105105

106106
#endif // MICROPY_NLR_X86

py/nlrxtensa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ NORETURN void nlr_jump(void *val) {
7777
: // clobbered registers
7878
);
7979

80-
for (;;); // needed to silence compiler warning
80+
MP_UNREACHABLE
8181
}
8282

8383
#endif // MICROPY_NLR_XTENSA

0 commit comments

Comments
 (0)