RFR: 8375536: PPC64: Implement special MachNodes for floating point CMove [v2]
Martin Doerr
mdoerr at openjdk.org
Wed Jan 28 16:41:32 UTC 2026
On Wed, 28 Jan 2026 09:45:14 GMT, Richard Reingruber <rrich at openjdk.org> wrote:
>> David Briemann has updated the pull request incrementally with one additional commit since the last revision:
>>
>> address review comments
>
> src/hotspot/cpu/ppc/c2_MacroAssembler_ppc.cpp line 684:
>
>> 682: xscmpeqdp(tmp, op1, op2);
>> 683: xxsel(dst, first, second, tmp);
>> 684: break;
>
> This looks incorrect to me.
>
> Also when I compare it with the disassembly of the C version[1]:
>
>
> double cmovf_eq(double op1, double op2, double src1, double src2) {
> return op1 == op2 ? src1 : src2;
> }
>
> cmovf_eq(double, double, double, double):
> xscmpeqdp 1,2,1
> xxsel 1,4,3,1
> blr
>
>
> `cc` would be 0xA for `==` (looking at `operand cmpOp`[2]), right?
> 0xA is 0b1010. `exchange` would be 0 but I think `src1` and `src2` need to be exchanged.
>
> Assume `op1` and `op2` are indeed equal in `op1 == op2 ? src1 : src2`. `tmp.dword[0]` will be set to 0xFFFF_FFFF_FFFF_FFFF by the `xscmpeqdp`.
>
> `xxsel` evaluates `(src1 & ~tmp) | (src2 & tmp)` so for the correct result `src1` and `src2` need to be swapped as also seen in the disassembly above.
>
> [1] [disassembly of the C version](https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGEgOykrgAyeAyYAHI%2BAEaYxCAArKQADqgKhE4MHt6%2BASlpGQKh4VEssfFJdpgOmUIETMQE2T5%2BXIFVNQJ1DQTFkTFxibb1jc25bcM9faXliQCUtqhexMjsHOYAzGHI3lgA1CYbbgoE%2BIIAdAiH2CYaAIKb27uYB0cn%2BKiX17cP9%2BhL0Xoe2QLFQADcqAB9TAARwg/y8gJeqGSXFIewRSL2K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pOp`](https://github.com/openjdk/jdk/blob/4ae4ffd5a3114aa2a3832818ee30dc38d9aa2b72/src/hotspot/...
Please note that C2 generates code which is equivalent to your C version:
xscmpeqdp vs0,vs1,vs2
xxsel vs1,vs4,vs3,vs0
It's correct because the condition is already inverted by C2 (cc == 2). But, the code is very confusing. I agree with that it should be improved.
Btw. what the Spec suggests also seems to use the wrong order:
xscmpeqdp can be used to implement the C/C++/Java conditional operation, RESULT = (x=y) ? a:b.
xscmpeqdp fEQ,fX,fY
xxsel fRESULT,fA,fB,fEQ
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29281#discussion_r2737516069
More information about the hotspot-compiler-dev
mailing list