JIT: emit float CMOV as branch-around-mov instead of flag-preserving blend - #973
Open
trethaller wants to merge 1 commit into
Open
JIT: emit float CMOV as branch-around-mov instead of flag-preserving blend#973trethaller wants to merge 1 commit into
trethaller wants to merge 1 commit into
Conversation
…blend The float conditional-move (used to resolve a float phi on a conditional edge, e.g. a `cond ? a : b` float ternary) had no cmovcc for XMM, so it was lowered to a branchless mask blend (setcc/neg/movq/andnpd/andpd/orpd). That arithmetic clobbers EFLAGS, but a following JCOND re-derives its condition from the same shared CMP (get_cond_jump skips over CMOV), so the blend had to be bracketed with pushfq/popfq to keep the flags alive. popfq is heavily microcoded and serializes the pipeline: on a hot particle-update loop it dominated the Core-Bound cycles (VTune: ~44% Serializing Operations). Emit a short jcc that skips a plain mov instead. A jcc reads EFLAGS but never writes them, so the shared compare survives naturally for the trailing JCOND. This drops the pushfq/popfq, the whole blend, and the stack spill the memory-operand path needed for ANDPD alignment. It mirrors the existing float CXCHG lowering right below this case. ~6% faster on the particle benchmark; output verified identical against the previous codegen (see Test_cmov.hx). Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.
Claude summary
I'll be honest I didn't get any of that
How I got here
I was benchmarking hide Emitter particles with VTune and noticed a lot of time was spend on a simple if(myenum != VZero) which should have been cheap.
The time was showing up under "Serializing Operations" which seemed weird, I'd have expected either cache miss on resolving the enum or branch prediction issues.
Feeding the assembly code to Claude led to this:
Results
Noticeable improvements in my particles benchmark.
Tested the new hl.exe with the SpaceCraft and Farever codebases and didn't notice any issue.