Re: [PATCH RFC 4/5] x86/alternative: Improve code generation readability
From: Peter Zijlstra
Date: Wed Apr 09 2025 - 10:43:36 EST
On Tue, Apr 08, 2025 at 01:21:17AM -0700, Josh Poimboeuf wrote:
> Improve the readability and compactness of alternatives code.
>
> ---------------------
> ALTERNATIVE() before:
> ---------------------
>
> # ALT: oldinstr
> 771:
> rep movsb
> 772:
> # ALT: padding
> .skip -(((775f-774f)-(772b-771b)) > 0) * ((775f-774f)-(772b-771b)),0x90
> 773:
> .pushsection .altinstructions,"a"
> .long 771b - .
> .long 774f - .
> .4byte (((1 << 0) << 16) | ((18*32+ 4)))
> .byte 773b-771b
> .byte 775f-774f
> .popsection
> .pushsection .altinstr_replacement, "ax"
> # ALT: replacement
> 774:
> call rep_movs_alternative
> 775:
> .popsection
>
> --------------------
> ALTERNATIVE() after:
> --------------------
>
> # <ALTERNATIVE>
> 771: rep movsb
> 772: .skip -(((775f-774f)-(772b-771b)) > 0) * ((775f-774f)-(772b-771b)),0x90
> 773:
> # ALT ENTRY:
> .pushsection .altinstructions,"a"; .long 771b - .; .long 774f - .; .4byte (((1 << 0) << 16) | ((18*32+ 4))); .byte 773b-771b; .byte 775f-774f; .popsection
I find this very hard to read. I prefer the multi line form it had
before.
Other than that, I like the new layout.
> # ALT REPLACEMENT:
> .pushsection .altinstr_replacement, "ax"
> 774: call rep_movs_alternative
> 775:
> .popsection
> # </ALTERNATIVE>