Open
Conversation
Contributor
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
x86.c:263
- Using -large_imm for non-positive values in mov_reg_large_imm is incorrect because it reverses the sign of negative immediates, potentially moving a different value than intended. Consider passing large_imm directly or handling negative values appropriately.
if (large_imm <= 0) { mov_reg_imm(dst, -large_imm); }
On x86, x86 instructions touching 32-bit registers generally zero-out the upper 32 bits of the register. Since xoring a register with itself is a common way to zero it out, we can use the 32-bit instruction to same the REX prefix and have a smaller instruction.
cb408cd to
6e1d544
Compare
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.
Making this PR to see if it reduces the execution time of dash and zsh, it may or may not be merged.
Context
On certain shells, scripts slow down the more variables there are in the environment. This is generally caused by the data structure storing the environment not being adapted to contain this many variables (i.e. dash's 37 entry hash table), and can make the execution time quadratic even when algorithms are linear, as each variable lookup takes a linear time. This means small memory reductions can significantly reduce execution time, as demonstrated in #77.
This PR optimizes the instruction encoding to use more compact encoding of common instructions:
This PR doesn't touch the exe code generator, where a lot more optimizations are possible but would increase code complexity.
Results
Methodology:
Other possible memory optimizations
The
codebuffer stores bytes of machine code but hasint[]as its type. Using the full 32 bits of ints could cut by 4 the number of environment variables used to store machine code, but labels rely on the extra space to store metadata that's used to resolve addresses that are not yet known.