public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Jinyang He <hejinyang@loongson.cn>,
	Chenghua Xu <xuchenghua@loongson.cn>,
	 Lulu Cheng <chenglulu@loongson.cn>
Cc: Weining Lu <luweining@loongson.cn>, Xing Li <lixing@loongson.cn>,
	yala <zhaojunchao@loongson.cn>, Peng Fan <fanpeng@loongson.cn>,
	 gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] LoongArch: Fix atomic_exchange make comparison and may jump out
Date: Tue, 15 Nov 2022 22:21:03 +0800	[thread overview]
Message-ID: <8039c23568889fe85afbe6940ed625448cf6cd56.camel@xry111.site> (raw)
In-Reply-To: <20221115130328.15413-1-hejinyang@loongson.cn>

On Tue, 2022-11-15 at 21:03 +0800, Jinyang He wrote:
> gcc/ChangeLog:
> 
> * config/loongarch/sync.md:
> Add atomic_cas_value_exchange_and_7<mode> and fix atomic_exchange<mode>.

nit:

	* config/loongarch/sync.md (atomic_cas_value_exchange_and_7): 
	New define_insn.
	(atomic_exchange): Use atomic_cas_value_exchange_and_7 instead 
	of atomic_cas_value_cmp_and.

> gcc/testsuite/ChangeLog:
>
> * gcc.target/loongarch/sync-1.c: New test.

Likewise, ChangeLog content should be indented with a tab. (Not 8
spaces: if my mail client changes my tab to 8 spaces I'm sorry).

/* snip */

> +  return "%G6\\n\\t"
> +        "1:\\n\\t"
> +        "ll.<amo>\\t%0,%1\\n\\t"
> +        "and\\t%7,%0,%z3\\n\\t"
> +        "or%i5\\t%7,%7,%5\\n\\t"
> +        "sc.<amo>\\t%7,%1\\n\\t"
> +        "beqz\\t%7,1b\\n\\t";

Do we need a "dbar 0x700" after beqz?

/* snip */

> diff --git a/gcc/testsuite/gcc.target/loongarch/sync-1.c b/gcc/testsuite/gcc.target/loongarch/sync-1.c
> new file mode 100644
> index 000000000..cebed6a9b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/sync-1.c
> @@ -0,0 +1,104 @@
> +/* Test __sync_test_and_set in atomic_exchange */
> +/* { dg-do run } */
> +/* { dg-options "-lpthread -std=c11" } */

This test seems not deterministic.  And the use of sched_yield is very
tricky, as the man page says:

       sched_yield() is intended for use with  real-time  scheduling  policies
       (i.e., SCHED_FIFO or SCHED_RR).  Use of sched_yield() with nondetermin‐
       istic scheduling policies such as SCHED_OTHER is unspecified  and  very
       likely means your application design is broken.

I'd suggest to create a bug report at https://gcc.gnu.org/bugzilla and
post this test in the PR.  Then add the PR number into the changelog,
and just add a { dg-do compile } and { dg-final { scan-assembler ... } }
test into the testsuite to ensure the correct ll/sc loop is generated.

A bug report also emphasises that this is a bug fix, which is suitable
for GCC 13 (in stage 3 now) and GCC 12 (the fix will be backported).

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2022-11-15 14:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 13:03 Jinyang He
2022-11-15 14:21 ` Xi Ruoyao [this message]
2022-11-16  2:11   ` Jinyang He
2022-11-16 11:46     ` Xi Ruoyao
2022-11-17  1:39       ` Jinyang He
2022-11-17  2:55         ` Jinyang He
2022-11-17  3:38           ` Xi Ruoyao
2022-11-17  3:46             ` Jinyang He
2022-11-17  5:56               ` Xi Ruoyao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8039c23568889fe85afbe6940ed625448cf6cd56.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=chenglulu@loongson.cn \
    --cc=fanpeng@loongson.cn \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hejinyang@loongson.cn \
    --cc=lixing@loongson.cn \
    --cc=luweining@loongson.cn \
    --cc=xuchenghua@loongson.cn \
    --cc=zhaojunchao@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).