Skip to content

Commit f63b4f8

Browse files
committed
py/parse: Work around xtensa esp-2020r3 compiler bug.
This commit works around a bug in xtensa-esp32-elf-gcc version esp-2020r3. The bug is in generation of loop constructs. The below code is generated by the xtensa-esp32 compiler. The first extract is the buggy machine code and the second extract is the corrected machine code. The test `basics/logic_constfolding.py` fails with the first code and succeeds with the second. Disassembly of section .text.push_result_rule: 00000000 <push_result_rule>: ... d6: 209770 or a9, a7, a7 d9: 178976 loop a9, f4 <push_result_rule+0xf4> d9: R_XTENSA_SLOT0_OP .text.push_result_rule+0xf4 dc: 030190 rsr.lend a9 df: 130090 wsr.lbeg a9 e2: a8c992 addi a9, a9, -88 e5: 06d992 addmi a9, a9, 0x600 e8: 130190 wsr.lend a9 eb: 002000 isync ee: 030290 rsr.lcount a9 f1: 01c992 addi a9, a9, 1 f4: 1494e7 bne a4, a14, 10c <push_result_rule+0x10c> f4: R_XTENSA_SLOT0_OP .text.push_result_rule+0x10c Disassembly of section .text.push_result_rule: 00000000 <push_result_rule>: ... d6: 209770 or a9, a7, a7 d9: 178976 loop a9, f4 <push_result_rule+0xf4> d9: R_XTENSA_SLOT0_OP .text.push_result_rule+0xf4 dc: 030190 rsr.lend a9 df: 130090 wsr.lbeg a9 e2: 000091 l32r a9, fffc00e4 <push_result_rule+0xfffc00e4> e2: R_XTENSA_SLOT0_OP .literal.push_result_rule+0x18 e5: 0020f0 nop e8: 130190 wsr.lend a9 eb: 002000 isync ee: 030290 rsr.lcount a9 f1: 01c992 addi a9, a9, 1 f4: 1494e7 bne a4, a14, 10c <push_result_rule+0x10c> f4: R_XTENSA_SLOT0_OP .text.push_result_rule+0x10c Work done in collaboration with @jimmo. Signed-off-by: Damien George <damien@micropython.org>
1 parent 3452ee5 commit f63b4f8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

ports/esp32/mpconfigport.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#define MICROPY_EMIT_XTENSAWIN (1)
3131
#endif
3232

33+
// workaround for xtensa-esp32-elf-gcc esp-2020r3, which can generate wrong code for loops
34+
// see https://github.com/espressif/esp-idf/issues/9130
35+
// this was fixed in newer versions of the compiler by:
36+
// "gas: use literals/const16 for xtensa loop relaxation"
37+
// https://github.com/jcmvbkbc/binutils-gdb-xtensa/commit/403b0b61f6d4358aee8493cb1d11814e368942c9
38+
#define MICROPY_COMP_CONST_FOLDING_COMPILER_WORKAROUND (1)
39+
3340
// optimisations
3441
#define MICROPY_OPT_COMPUTED_GOTO (1)
3542

py/parse.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,11 @@ STATIC MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table);
639639
STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args);
640640

641641
#if MICROPY_COMP_CONST_FOLDING
642+
#if MICROPY_COMP_CONST_FOLDING_COMPILER_WORKAROUND
643+
// Some versions of the xtensa-esp32-elf-gcc compiler generate wrong code if this
644+
// function is static, so provide a hook for them to work around this problem.
645+
MP_NOINLINE
646+
#endif
642647
STATIC bool fold_logical_constants(parser_t *parser, uint8_t rule_id, size_t *num_args) {
643648
if (rule_id == RULE_or_test
644649
|| rule_id == RULE_and_test) {

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