Re: [PATCH RESEND] mshv: Use try_cmpxchg() instead of cmpxchg()
From: Wei Liu
Date: Wed Feb 18 2026 - 18:27:56 EST
On Wed, Feb 18, 2026 at 12:00:18PM +0100, Uros Bizjak wrote:
> Use !try_cmpxchg() instead of cmpxchg (*ptr, old, new) != old.
> x86 CMPXCHG instruction returns success in ZF flag, so this
> change saves a compare after CMPXCHG.
>
> The generated assembly code improves from e.g.:
>
> 415: 48 8b 44 24 30 mov 0x30(%rsp),%rax
> 41a: 48 8b 54 24 38 mov 0x38(%rsp),%rdx
> 41f: f0 49 0f b1 91 a8 02 lock cmpxchg %rdx,0x2a8(%r9)
> 426: 00 00
> 428: 48 3b 44 24 30 cmp 0x30(%rsp),%rax
> 42d: 0f 84 09 ff ff ff je 33c <...>
>
> to:
>
> 415: 48 8b 44 24 30 mov 0x30(%rsp),%rax
> 41a: 48 8b 54 24 38 mov 0x38(%rsp),%rdx
> 41f: f0 49 0f b1 91 a8 02 lock cmpxchg %rdx,0x2a8(%r9)
> 426: 00 00
> 428: 0f 84 0e ff ff ff je 33c <...>
>
> No functional change intended.
>
> Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
> Cc: "K. Y. Srinivasan" <kys@xxxxxxxxxxxxx>
> Cc: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>
> Cc: Wei Liu <wei.liu@xxxxxxxxxx>
> Cc: Dexuan Cui <decui@xxxxxxxxxxxxx>
> Cc: Long Li <longli@xxxxxxxxxxxxx>
Applied. Thanks.