-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
py/emitinlinerv32: Reduce footprint and fix build on ESP32. #16524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #16524 +/- ##
=======================================
Coverage 98.53% 98.53%
=======================================
Files 169 169
Lines 21852 21852
=======================================
Hits 21532 21532
Misses 320 320 ☔ View full report in Codecov by Sentry. |
Code size report:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks good to me, but tbh I'm not expert enough on either the native emitters or RISC-V instruction encodings to understand it deeply. 😁
I'm going to mark this against the 1.26 release so it doesn't get forgotten about, though.
py/emitinlinerv32.c
Outdated
{ MP_QSTR_sw, asm_rv32_opcode_sw, CALL_RIR, R, 0, I, 0, R, 0, 0xFFFFFFFF, 0x00000FFF, 0xFFFFFFFF }, | ||
{ MP_QSTR_xor, asm_rv32_opcode_xor, CALL_RRR, R, 0, R, 0, R, 0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF }, | ||
{ MP_QSTR_xori, asm_rv32_opcode_xori, CALL_RRI, R, 0, R, 0, I, 0, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000FFF }, | ||
{ MP_QSTR_add, 0x00, 0x00, 0x00, 3, CALL_RRR, R, 0, R, 0, R, 0, asm_rv32_opcode_add }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These mask indices are quite cryptic, it's not obvious they index OPCODE_MASKS
.
I suggest making an enum for them, eg:
enum {
MASK_FFFFFFFF,
MASK_00000FFF,
MASK_FFFFF000,
...
};
then define OPCODE_MASKS
to ensure they indices match:
static const uint32_t OPCODE_MASKS[] = {
[MASK_FFFFFFFF] = 0xFFFFFFFF,
[MASK_00000FFF] = 0x00000FFF,
[MASK_FFFFF000] = 0xFFFFF000,
...
};
and then use these indices in this table here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I've modified the code as you suggested. Too bad now the table doesn't look as neat, since NONE
was the same length of a raw mask index and I couldn't come up with an 8 characters long equivalent :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use MASK_NOT_USED
, or just MASK_________
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I used MASK_NOT_USED
. Wonder why I didn't think of that myself... :)
This commit fixes a compilation warning (turned error) about a potentially uninitialised variable being used. The warning can be ignored as the variable in question is always written to, but the code has been changed to silence that warning. Signed-off-by: Alessandro Gatti <[email protected]>
ca2929c
to
80f85d8
Compare
This commit introduces a few changes aimed at reducing the amount of space taken by the inline assembler once compiled: * The register string table uses 2 bytes for each qstr rather than the usual 4 * The opcode table uses 2 bytes for each qstr rather than the usual 4 * Opcode masks are not embedded in each opcode entry but looked up via an additional smaller table, reducing the number of bytes taken by an opcode's masks from 12 to 2 (with a fixed overhead of 24 bytes for the the masks themselves stored elsewhere) * Some error messages had a trailing period, now removed * Error messages have been parameterised when possible, and the overall text length is smaller. Signed-off-by: Alessandro Gatti <[email protected]>
80f85d8
to
8633abc
Compare
Summary
This PR fixes a warning occurring on the compiler version shipped with ESP-IDF v5.2.0 and later, and incorporates the suggestions made in #15714 to reduce the overall footprint.
The size reduction for QEMU/VIRT_RV32 is 975 bytes, on ESP32 should probably be close to that.
This PR can wait for v1.25.0 to get out first, there's no improvement in functionality or any critical bugfixes compared to #15714 (ESP32 has this feature turned off by default anyway).
Testing
The inlineasm tests passed successfully on both QEMU and an ESP32C3 using ESP-IDF v5.2.0.