* [PATCH v3] LoongArch: Fixed a compilation failure with '%c' in inline assembly [PR107731].
@ 2022-12-09 9:41 Lulu Cheng
2022-12-09 10:03 ` Richard Sandiford
0 siblings, 1 reply; 2+ messages in thread
From: Lulu Cheng @ 2022-12-09 9:41 UTC (permalink / raw)
To: gcc-patches, pinskia, richard.sandiford
Cc: xry111, i, xuchenghua, Lulu Cheng, Yang Yujie
There is description of '%c' "%n" "%a" and "%l" in section 17.5 of gccint.pdf.
So I can understand that these descriptors are the ones that the common code
implementation back end has to support, right?
But I don't see the use of these descriptors in gcc.pdf.Now I want to add the
descriptor information under loongarch. I had to add '%c' to the schema section.
Is there a better solution to this?
V2 -> v3:
1. Correct a clerical error.
2. Adding document for loongarch operand modifiers.
---
Co-authored-by: Yang Yujie <yangyujie@loongson.cn>
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.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/tst-asm-const.c: Moved to...
* gcc.target/loongarch/pr107731.c: ...here.
---
gcc/config/loongarch/loongarch.cc | 14 ++++++++++++++
gcc/doc/extend.texi | 16 ++++++++++++++++
.../loongarch/{tst-asm-const.c => pr107731.c} | 6 +++---
3 files changed, 33 insertions(+), 3 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 b1dd39e64b8..5a8b9489f3d 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -11374,6 +11374,22 @@ 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{c} @tab Print a constant integer operand in decimal.
+@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)
:
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v3] LoongArch: Fixed a compilation failure with '%c' in inline assembly [PR107731].
2022-12-09 9:41 [PATCH v3] LoongArch: Fixed a compilation failure with '%c' in inline assembly [PR107731] Lulu Cheng
@ 2022-12-09 10:03 ` Richard Sandiford
0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2022-12-09 10:03 UTC (permalink / raw)
To: Lulu Cheng; +Cc: gcc-patches, pinskia, xry111, i, xuchenghua, Yang Yujie
Lulu Cheng <chenglulu@loongson.cn> writes:
> There is description of '%c' "%n" "%a" and "%l" in section 17.5 of gccint.pdf.
> So I can understand that these descriptors are the ones that the common code
> implementation back end has to support, right?
> But I don't see the use of these descriptors in gcc.pdf.Now I want to add the
> descriptor information under loongarch. I had to add '%c' to the schema section.
> Is there a better solution to this?
It looks right to me FWIW. I agree it seems odd that %c, %n, %a and %l
aren't mentioned in the user-facing documentation, given that md.texi
implies that all targets must support them. Looks like the user
documentation just says "Typically these qualifiers are hardware
dependent.", without hinting what the 4 atypical cases are.
Thanks,
Richard
>
>
> V2 -> v3:
> 1. Correct a clerical error.
> 2. Adding document for loongarch operand modifiers.
>
> ---
>
> Co-authored-by: Yang Yujie <yangyujie@loongson.cn>
>
> 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.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/loongarch/tst-asm-const.c: Moved to...
> * gcc.target/loongarch/pr107731.c: ...here.
> ---
> gcc/config/loongarch/loongarch.cc | 14 ++++++++++++++
> gcc/doc/extend.texi | 16 ++++++++++++++++
> .../loongarch/{tst-asm-const.c => pr107731.c} | 6 +++---
> 3 files changed, 33 insertions(+), 3 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 b1dd39e64b8..5a8b9489f3d 100644
> --- a/gcc/doc/extend.texi
> +++ b/gcc/doc/extend.texi
> @@ -11374,6 +11374,22 @@ 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{c} @tab Print a constant integer operand in decimal.
> +@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)
> :
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-09 10:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-09 9:41 [PATCH v3] LoongArch: Fixed a compilation failure with '%c' in inline assembly [PR107731] Lulu Cheng
2022-12-09 10:03 ` Richard Sandiford
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).