public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmerdabbelt@google.com>
To: gcc-patches@gcc.gnu.org
Cc: Jim Wilson <jimw@sifive.com>,
	bmeng.cn@gmail.com, Andrew Waterman <andrew@sifive.com>,
	Palmer Dabbelt <palmerdabbelt@google.com>
Subject: [PATCH] RISC-V: Implement __clear_cache via __builtin__clear_cache
Date: Thu, 29 Apr 2021 21:56:46 -0700	[thread overview]
Message-ID: <20210430045646.1508805-1-palmerdabbelt@google.com> (raw)

We have had an implementation of __builtin__clear_cache since the
beginning, but didn't have the cooresponding __clear_cache library
routine implemented.  This directly conflicts the GCC manual in a
handful of places, which indicates that __clear_cache should work and
that __builtin_clear_cache should function the same way as
__clear_cache by ethier calling it or inlining the functionality.

This patch simply implements __clear_cache via __builtin__clear_cache.
This should be safe as we always have clear_cache insn so therefor
__builtin__clear_cache will never fall back to calling __clear_cache.
I'm not actually sure that silently implementing clear_cache as a NOP
when there is no ISA defined mechanism for icache synchronization is the
right way to go, but that's really a different discussion.

This was reported as Bug 94136, which is a year old but was categorized
as a documentation bug.  I believe that categorization was incorrect:
having an empty __clear_cache library routine is simply incorrect
behavior, the fact that __builtin__clear_cache happens to be implemented
as a libc call on Linux is just a red herring suggesting the
documentation fix to point out the name difference.  I view this new
behavior as conforming to the existing documentation: we're just
inlining the __clear_cache implementation, even if that implementation
happens to be a call to a very similar looking libc routine.

gcc/ChangeLog
	PR target/94136
	* config/riscv/riscv.h (CLEAR_INSN_CACHE): New macro.

---

Something has gone off the rails with my laptop and it's failing to
build GCC, so I haven't actually tested this.  I'm not sure it's sane to
call a GCC builtin from within libgcc, but I figured it would be best to
just send out the patch to ask.
---
 gcc/config/riscv/riscv.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index f3e85723c85..39a688ea1e9 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -993,4 +993,9 @@ extern void riscv_remove_unneeded_save_restore_calls (void);
 
 #define HARD_REGNO_RENAME_OK(FROM, TO) riscv_hard_regno_rename_ok (FROM, TO)
 
+/* We always have a "clear_cache" insn, which means __builtin__clear_cache will
+   never emit a call to __clear_cache.  */
+#undef CLEAR_INSN_CACHE
+#define CLEAR_INSN_CACHE(BEG, END) __builtin__clear_cache((BEG), (END));
+
 #endif /* ! GCC_RISCV_H */
-- 
2.31.1.527.g47e6f16901-goog


             reply	other threads:[~2021-04-30  5:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-30  4:56 Palmer Dabbelt [this message]
2021-05-01  5:23 ` Jim Wilson

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=20210430045646.1508805-1-palmerdabbelt@google.com \
    --to=palmerdabbelt@google.com \
    --cc=andrew@sifive.com \
    --cc=bmeng.cn@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jimw@sifive.com \
    /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).