(https://sourceware.org/pipermail/binutils/2024-May/134009.html RFC: Maintaining a per-macro invocation count) gas recently introduced \+ for per-macro invocation counts within .macro/.endm directives. Building on discussions at https://sourceware.org/pipermail/binutils/2024-May/134089.html , extending the feature to loop directives would be beneficial. This would allow us to replace .byte 0, 1, 2 with: .rept 3 .byte \+ .endr (.irpc i,0123456789 \i .endr) works for a loop when the count is <= 10 but is cumbersome for larger loop counts. For nested loops, \+ could indicate the outermost loop for implementation convenience. Such constructs are rare and we can rely on clear documentation. .rept 2 .rept 2 .byte \+ .endr .endr # 0 0 1 1
In the absence of the feature, there are a few ways, but none achieves great efficiency or convenience. For example, we can define a macro that expands to a sequence of strings: 0, (0+1), ((0+1)+1), (((0+1)+1)+1), ... % cat a.s .data .macro iota n, i=0 .if \n-\i .byte \i iota \n, "(\i+1)" .endif .endm iota 16 % as a.s -o a.o % readelf -x .data a.o Hex dump of section '.data': 0x00000000 00010203 04050607 08090a0b 0c0d0e0f ................ --- % in altmacro allows: % cat a.s .data .altmacro .macro iota n, i=0 .if \n-\i .byte \i iota \n, %(\i+1) .endif .endm iota 16 % as a.s -o a.o % readelf -x .data a.o Hex dump of section '.data': 0x00000000 00010203 04050607 08090a0b 0c0d0e0f ................
The master branch has been updated by Jan Beulich <jbeulich@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f29ebbe3be5c2a4400ad8b89a8f399ead4448148 commit f29ebbe3be5c2a4400ad8b89a8f399ead4448148 Author: Jan Beulich <jbeulich@suse.com> Date: Fri May 24 12:23:22 2024 +0200 gas: extend \+ support to .irp / .irpc PR gas/31752 These are effectively macro-like, without any separate macro definition. They already support \@, so they would better also support \+. This allows, where desired, to get away without maintaining an explicit count variable in source code. With this the recently introduced testcase doesn't need any xfails anymore.
The master branch has been updated by Jan Beulich <jbeulich@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1e3c814459d83247707f8c9840ac660726cfaae0 commit 1e3c814459d83247707f8c9840ac660726cfaae0 Author: Jan Beulich <jbeulich@suse.com> Date: Mon Jun 10 09:06:37 2024 +0200 gas: extend \+ support to .rept PR gas/31752 While not quite as macro-like as .irp / .irpc, this perhaps benefits from supporting \+ even more than those: It allows, where desired, to get away without maintaining an explicit count variable in source code. Keep .rep (and custom per-arch uses of s_rept() / do_repeat()) behavior unaltered.
Should be all set now.