https://gcc.gnu.org/g:ca94c21cf8faa4a7364654a4377d31b01ba27efa
commit r17-1050-gca94c21cf8faa4a7364654a4377d31b01ba27efa Author: Georg-Johann Lay <[email protected]> Date: Sun May 31 10:11:35 2026 +0200 AVR: Support [[len=nl]] in asm templates. Most inline asm consists of 1-word instruction, so their exact size can be conveniently specified with [[len=nl]], which is half the default size. gcc/ * config/avr/avr.cc (avr_length_of_asm): Support "nl" as the number of lines in the code template. * doc/extend.texi (Size of an asm): Document [[len=nl]]. Simplify the description of the default length. Diff: --- gcc/config/avr/avr.cc | 13 +++++++++++++ gcc/doc/extend.texi | 11 ++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index c6443c03423a..2f0ed2e491ab 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -11156,6 +11156,10 @@ avr_read_number (const char *start, const char **end) then return -1. Otherwise, return the sum over all [[len=<words>]] annotations, where: + <words> = nl + The number of lines in the code template. + This is half the default size. + <words> = [0-9]+ Specifies a non-negative decimal integer. @@ -11215,6 +11219,13 @@ avr_length_of_asm (rtx_insn *insn, int default_len, const char *tpl, else if (startswith (pos, "call")) pos += 4; } + else if (startswith (pos, "nl")) + { + // "nl" denotes the number of lines in the code template, + // which is half of the default length. + inc = asm_str_count (tpl); + pos += 2; + } else if (startswith (pos, "lds") || startswith (pos, "sts")) { @@ -11255,6 +11266,8 @@ avr_length_of_asm (rtx_insn *insn, int default_len, const char *tpl, if (pos_end) strncat (msg, pos_end - 4, 4); } + else if (pos_end) + msg[l_pos] = '\0'; if (pos_end) strcat (msg, len_end); diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index f4d92467826a..5e14f0cf523a 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -13477,6 +13477,11 @@ The following @code{@var{spec}}'s are supported. They specify the size of the @code{asm} --- or parts of it --- in units of 16-bit words: @table @code +@item nl +The number of lines in the code template, which is half the default size. +It suits code templates that only use 1-word instructions with +no superfuous physical @samp{\n} or logical @samp{$} line breaks. + @item [0-9]+ The decimal representation of a non-negative integer. @@ -13526,9 +13531,9 @@ number of physical and logical line breaks. Such cases can lead to errors when a jump that uses a too optimistic jump offset is crossing such assembly code. @item Better code generation for jumps that are crossing an @code{asm}. -The default length of an asm is (1 + @var{NL}) * 2 words, where @var{NL} -denotes the sum of physical and logical line breaks. However, almost -all AVR instructions occupy only a single 16-bit word. +The default length in words is @emph{twice} the number of lines in +the code template, though almost all AVR instructions occupy only +@emph{one} 16-bit word. @end itemize
