Add a few optimizations to reduce the number of copies #194
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.
This adds infrastructure to delay the assembly of values so that they can if appropriate target the stack directly instead of always having to resort to copy the value from a position in the stack to the top of it.
This has several benefits:
IndexGet
operation (see use ofStack::address_ref
which can even use a reference of the value).My own benchmarks shows a 50% reduction in the number of copies in
aoc_2020_1a
and a ~10% performance gain.Because this has to live side-by-side with the existing assembler,
Asm
has to support both modes:Asm::apply
will cause the assembly to generate the necessary instructions. No compiler state will be modified, since this is currently the norm.Asm::apply_targeted
will produce anInstTarget
appropriate for the operation. If a value is copied onto the stack, it will be declared as anonymous. This should be used immediately in a scope so the scope can be cleaned up.