tools/mpy_ld.py: Optimise entry trampoline for x86/x64.#19309
Open
agatti wants to merge 1 commit into
Open
Conversation
This commit allows natmod entry trampolines to possibly be smaller depending on the offset between the `mpy_init` from the beginning of the text segment. x64 and x86 shared the same, fixed-size entry point opcode that covered the whole 32-bits offset range. With changes introduced in 0fd0843 the entry point may change its length once all segments are laid out in the file, so optimised entry point code sequences can be emitted depending on the jump distance. These changes generate optimised entry point jump opcodes for 8-, and 32- bit offsets. Depending on the size of the natmod and where the compiler decides to put the `mpy_init` symbol this can help shortening the output file by three bytes. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
c5e1a3c to
723ffb1
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19309 +/- ##
=======================================
Coverage 98.47% 98.47%
=======================================
Files 176 176
Lines 22845 22845
=======================================
Hits 22497 22497
Misses 348 348 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code size report: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR allows natmod entry trampolines to possibly be smaller depending on the offset between the
mpy_initfrom the beginning of the text segment.x64 and x86 shared the same, fixed-size entry point opcode that covered the whole 32-bits offset range. With changes introduced in 0fd0843 the entry point may change its length once all segments are laid out in the file, so optimised entry point code sequences can be emitted depending on the jump distance.
These changes generate optimised entry point jump opcodes for 8-, and 32- bit offsets. Depending on the size of the natmod and where the compiler decides to put the
mpy_initsymbol this can help shortening the output file by three bytes. Clang seems to prefer placingmpy_initat the beginning of the text segment on x86, whilst GCC sort of does it on x64. In both cases, a 2 bytes opcode is used instead of a 6 bytes one.This is derived from the work being carried out in #19308, as this change won't really fit the parent PR's scope.
Testing
This should be tested by CI, as x86 and x64 natmod tests should be covered. In addition, the
features0natmod is small enough to trigger the generation of a 8-bit jump. Importing that module on either a x86 or x64 interpreter and running itsfactorialfunction works as expected.Generative AI
I did not use generative AI tools when creating this PR.