Branch on Bool
alpha
in scaling mul!
#1286
Merged
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.
By dealing with the
alpha == 0
case separately, we ensure that ifalpha::Bool
, it must betrue
. This reduces the branches in_lscale_add
from 4 to 2 in the common case of 3-argumentmul!
. This leads to a latency reduction, as each branch has to compile a different broadcast expression, and we currently compile four but use only one. Primarily, this PR leads to a reduction in allocations.Something similar usually doesn't lead to a big gain in the
_rscale_add
method, ass * alpha
often has the same type ass
, and therefore the branches onalpha
compile the same code.