From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id F3A753858D32; Tue, 17 Jan 2023 01:07:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3A753858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.20.4.52]) by gateway (Coremail) with SMTP id _____8Dxi+rW9MVjZP8BAA--.6216S3; Tue, 17 Jan 2023 09:07:35 +0800 (CST) Received: from [10.20.4.52] (unknown [10.20.4.52]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxsOTV9MVjK4IaAA--.15242S2; Tue, 17 Jan 2023 09:07:34 +0800 (CST) Subject: Re: [PATCH v5] LoongArch: Fixed a compilation failure with '%c' in inline assembly [PR107731]. To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Cc: pinskia@gcc.gnu.org, xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, Yang Yujie References: <20230113032755.3318339-1-chenglulu@loongson.cn> From: Lulu Cheng Message-ID: <046e8aa5-7029-9cb1-31e7-07c4ec153dfb@loongson.cn> Date: Tue, 17 Jan 2023 09:07:33 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20230113032755.3318339-1-chenglulu@loongson.cn> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8BxsOTV9MVjK4IaAA--.15242S2 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBjvJXoW3urWDGF43trWxZF15Ww1DAwb_yoWDWryrpr 47uw1qgFsrCFn7Wa1kA3yrurZ8Jrsrtr429ayftry0kwnxt34jqF4IyF9Fq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MARC_STATUS,KAM_SHORT,MIME_CHARSET_FARAWAY,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Ping? ÔÚ 2023/1/13 ÉÏÎç11:27, Lulu Cheng дµÀ: > Co-authored-by: Yang Yujie > > gcc/ChangeLog: > > * config/loongarch/loongarch.cc (loongarch_classify_address): > Add precessint for CONST_INT. > (loongarch_print_operand_reloc): Operand modifier 'c' is supported. > (loongarch_print_operand): Increase the processing of '%c'. > * doc/extend.texi: Adds documents for LoongArch operand modifiers. > And port the public operand modifiers information to this document. > > gcc/testsuite/ChangeLog: > > * gcc.target/loongarch/tst-asm-const.c: Moved to... > * gcc.target/loongarch/pr107731.c: ...here. > > --- > V2 -> v3: > 1. Correct a clerical error. > 2. Adding document for loongarch operand modifiers. > > v3 -> v4: > Copy the description of "%c" "%n" "%a" "%l" from gccint.pdf to gcc.pdf. > > v4 -> v5: > Move the operand modifiers description of "%c", "%n", "%a", "%l" to the top of the > x86Operandmodifiers section. > > --- > gcc/config/loongarch/loongarch.cc | 14 ++ > gcc/doc/extend.texi | 135 ++++++++++++------ > .../loongarch/{tst-asm-const.c => pr107731.c} | 6 +- > 3 files changed, 106 insertions(+), 49 deletions(-) > rename gcc/testsuite/gcc.target/loongarch/{tst-asm-const.c => pr107731.c} (78%) > > diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc > index c6b03fcf2f9..cdf190b985e 100644 > --- a/gcc/config/loongarch/loongarch.cc > +++ b/gcc/config/loongarch/loongarch.cc > @@ -2075,6 +2075,11 @@ loongarch_classify_address (struct loongarch_address_info *info, rtx x, > return (loongarch_valid_base_register_p (info->reg, mode, strict_p) > && loongarch_valid_lo_sum_p (info->symbol_type, mode, > info->offset)); > + case CONST_INT: > + /* Small-integer addresses don't occur very often, but they > + are legitimate if $r0 is a valid base register. */ > + info->type = ADDRESS_CONST_INT; > + return IMM12_OPERAND (INTVAL (x)); > > default: > return false; > @@ -4933,6 +4938,7 @@ loongarch_print_operand_reloc (FILE *file, rtx op, bool hi64_part, > > 'A' Print a _DB suffix if the memory model requires a release. > 'b' Print the address of a memory operand, without offset. > + 'c' Print an integer. > 'C' Print the integer branch condition for comparison OP. > 'd' Print CONST_INT OP in decimal. > 'F' Print the FPU branch condition for comparison OP. > @@ -4979,6 +4985,14 @@ loongarch_print_operand (FILE *file, rtx op, int letter) > fputs ("_db", file); > break; > > + case 'c': > + if (CONST_INT_P (op)) > + fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op)); > + else > + output_operand_lossage ("unsupported operand for code '%c'", letter); > + > + break; > + > case 'C': > loongarch_print_int_branch_condition (file, code, letter); > break; > diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi > index 1103e9936f7..256811cb8f5 100644 > --- a/gcc/doc/extend.texi > +++ b/gcc/doc/extend.texi > @@ -10402,8 +10402,10 @@ ensures that modifying @var{a} does not affect the address referenced by > is undefined if @var{a} is modified before using @var{b}. > > @code{asm} supports operand modifiers on operands (for example @samp{%k2} > -instead of simply @samp{%2}). Typically these qualifiers are hardware > -dependent. The list of supported modifiers for x86 is found at > +instead of simply @samp{%2}). @ref{GenericOperandmodifiers, > +Generic Operand modifiers} lists the modifiers that are available > +on all targets. Other modifiers are hardware dependent. > +For example, the list of supported modifiers for x86 is found at > @ref{x86Operandmodifiers,x86 Operand modifiers}. > > If the C code that follows the @code{asm} makes no use of any of the output > @@ -10671,8 +10673,10 @@ optimizers may discard the @code{asm} statement as unneeded > (see @ref{Volatile}). > > @code{asm} supports operand modifiers on operands (for example @samp{%k2} > -instead of simply @samp{%2}). Typically these qualifiers are hardware > -dependent. The list of supported modifiers for x86 is found at > +instead of simply @samp{%2}). @ref{GenericOperandmodifiers, > +Generic Operand modifiers} lists the modifiers that are available > +on all targets. Other modifiers are hardware dependent. > +For example, the list of supported modifiers for x86 is found at > @ref{x86Operandmodifiers,x86 Operand modifiers}. > > In this example using the fictitious @code{combine} instruction, the > @@ -11024,9 +11028,8 @@ lab: > @} > @end example > > -@anchor{x86Operandmodifiers} > -@subsubsection x86 Operand Modifiers > - > +@anchor{GenericOperandmodifiers} > +@subsubsection Generic Operand Modifiers > References to input, output, and goto operands in the assembler template > of extended @code{asm} statements can use > modifiers to affect the way the operands are formatted in > @@ -11045,48 +11048,31 @@ These modifiers generate this assembler code: > xchg %ah, %al > @end example > > -The rest of this discussion uses the following code for illustrative purposes. > - > -@example > -int main() > -@{ > - int iInt = 1; > - > -top: > - > - asm volatile goto ("some assembler instructions here" > - : /* No outputs. */ > - : "q" (iInt), "X" (sizeof(unsigned char) + 1), "i" (42) > - : /* No clobbers. */ > - : top); > -@} > -@end example > - > -With no modifiers, this is what the output from the operands would be > -for the @samp{att} and @samp{intel} dialects of assembler: > +@noindent > +The following table shows the modifiers supported by generic and their effects > > -@multitable {Operand} {$.L2} {OFFSET FLAT:.L2} > -@headitem Operand @tab @samp{att} @tab @samp{intel} > -@item @code{%0} > -@tab @code{%eax} > -@tab @code{eax} > -@item @code{%1} > -@tab @code{$2} > -@tab @code{2} > -@item @code{%3} > -@tab @code{$.L3} > -@tab @code{OFFSET FLAT:.L3} > -@item @code{%4} > -@tab @code{$8} > -@tab @code{8} > -@item @code{%5} > -@tab @code{%xmm0} > -@tab @code{xmm0} > -@item @code{%7} > -@tab @code{$0} > -@tab @code{0} > +@multitable {Modifier} {Print the opcode suffix for the size of th} {Operand} > +@headitem Modifier @tab Description @tab Operand > +@item @code{c} > +@tab Require a constant operand and print the constant expression with no punctuation. > +@tab @code{%c0} > +@item @code{n} > +@tab Like @samp{%c} except that the value of the constant is negated before printing. > +@tab @code{%n0} > +@item @code{a} > +@tab Substitutes a memory reference, with the actual operand treated as the address. > +This may be useful when outputting a ``load address'' instruction, because > +often the assembler syntax for such an instruction requires you to write the > +operand as if it were a memory reference. > +@tab @code{%a0} > +@item @code{l} > +@tab Print the label name with no punctuation. > +@tab @code{%l0} > @end multitable > > +@anchor{x86Operandmodifiers} > +@subsubsection x86 Operand Modifiers > + > The table below shows the list of supported modifiers and their effects. > > @multitable {Modifier} {Print the opcode suffix for the size of th} {Operand} {@samp{att}} {@samp{intel}} > @@ -11243,6 +11229,48 @@ delimiterprint the opcode suffix of s. > @tab Like @code{z}, with special suffixes for x87 instructions. > @end multitable > > +The rest of this discussion uses the following code for illustrative purposes. > + > +@example > +int main() > +@{ > + int iInt = 1; > + > +top: > + > + asm volatile goto ("some assembler instructions here" > + : /* No outputs. */ > + : "q" (iInt), "X" (sizeof(unsigned char) + 1), "i" (42) > + : /* No clobbers. */ > + : top); > +@} > +@end example > + > +With no modifiers, this is what the output from the operands would be > +for the @samp{att} and @samp{intel} dialects of assembler: > + > +@multitable {Operand} {$.L2} {OFFSET FLAT:.L2} > +@headitem Operand @tab @samp{att} @tab @samp{intel} > +@item @code{%0} > +@tab @code{%eax} > +@tab @code{eax} > +@item @code{%1} > +@tab @code{$2} > +@tab @code{2} > +@item @code{%3} > +@tab @code{$.L3} > +@tab @code{OFFSET FLAT:.L3} > +@item @code{%4} > +@tab @code{$8} > +@tab @code{8} > +@item @code{%5} > +@tab @code{%xmm0} > +@tab @code{xmm0} > +@item @code{%7} > +@tab @code{$0} > +@tab @code{0} > +@end multitable > + > > @anchor{x86floatingpointasmoperands} > @subsubsection x86 Floating-Point @code{asm} Operands > @@ -11374,6 +11402,21 @@ constant. Used to select the specified bit position. > @item @code{x} @tab Equivialent to @code{X}, but only for pointers. > @end multitable > > +@anchor{loongarchOperandmodifiers} > +@subsubsection LoongArch Operand Modifiers > + > +The list below describes the supported modifiers and their effects for LoongArch. > + > +@multitable @columnfractions .10 .90 > +@headitem Modifier @tab Description > +@item @code{d} @tab Same as @code{c}. > +@item @code{i} @tab Print the character ''@code{i}'' if the operand is not a register. > +@item @code{m} @tab Same as @code{c}, but the printed value is @code{operand - 1}. > +@item @code{X} @tab Print a constant integer operand in hexadecimal. > +@item @code{z} @tab Print the operand in its unmodified form, followed by a comma. > +@end multitable > + > + > @lowersections > @include md.texi > @raisesections > diff --git a/gcc/testsuite/gcc.target/loongarch/tst-asm-const.c b/gcc/testsuite/gcc.target/loongarch/pr107731.c > similarity index 78% > rename from gcc/testsuite/gcc.target/loongarch/tst-asm-const.c > rename to gcc/testsuite/gcc.target/loongarch/pr107731.c > index 2e04b99e301..80d84c48c6e 100644 > --- a/gcc/testsuite/gcc.target/loongarch/tst-asm-const.c > +++ b/gcc/testsuite/gcc.target/loongarch/pr107731.c > @@ -1,13 +1,13 @@ > -/* Test asm const. */ > /* { dg-do compile } */ > /* { dg-final { scan-assembler-times "foo:.*\\.long 1061109567.*\\.long 52" 1 } } */ > + > int foo () > { > __asm__ volatile ( > "foo:" > "\n\t" > - ".long %a0\n\t" > - ".long %a1\n\t" > + ".long %c0\n\t" > + ".long %c1\n\t" > : > :"i"(0x3f3f3f3f), "i"(52) > :