* [PATCH v2] RISC-V: Implement __clear_cache via __builtin___clear_cache
@ 2022-10-14 19:56 Palmer Dabbelt
2022-10-14 21:59 ` Palmer Dabbelt
0 siblings, 1 reply; 2+ messages in thread
From: Palmer Dabbelt @ 2022-10-14 19:56 UTC (permalink / raw)
To: gcc-patches, Jim Wilson; +Cc: Palmer Dabbelt
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.
---
Passes riscv-linux mulilib with no new failures. OK for trunk and
backports to gcc-11, gcc-12?
Changes since v1 <20210430045646.1508805-1-palmerdabbelt@google.com>:
* Extra "_" as per Jim's comment.
---
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 acae68ebb2d..bb0dcb651d5 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -1080,4 +1080,9 @@ extern void riscv_remove_unneeded_save_restore_calls (void);
#define REGISTER_TARGET_PRAGMAS() riscv_register_pragmas ()
+/* 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.38.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] RISC-V: Implement __clear_cache via __builtin___clear_cache
2022-10-14 19:56 [PATCH v2] RISC-V: Implement __clear_cache via __builtin___clear_cache Palmer Dabbelt
@ 2022-10-14 21:59 ` Palmer Dabbelt
0 siblings, 0 replies; 2+ messages in thread
From: Palmer Dabbelt @ 2022-10-14 21:59 UTC (permalink / raw)
To: gcc-patches, Jim Wilson
On Fri, 14 Oct 2022 12:56:48 PDT (-0700), Palmer Dabbelt wrote:
> 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.
>
> ---
>
> Passes riscv-linux mulilib with no new failures. OK for trunk and
Oops, accidentally hit send before checking the test results. There's a
bunch of failures, not sure if they're new though as I was trying to
bisect them down and have a dirty tree. This might take a few
minutes...
> backports to gcc-11, gcc-12?
>
> Changes since v1 <20210430045646.1508805-1-palmerdabbelt@google.com>:
>
> * Extra "_" as per Jim's comment.
> ---
> 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 acae68ebb2d..bb0dcb651d5 100644
> --- a/gcc/config/riscv/riscv.h
> +++ b/gcc/config/riscv/riscv.h
> @@ -1080,4 +1080,9 @@ extern void riscv_remove_unneeded_save_restore_calls (void);
>
> #define REGISTER_TARGET_PRAGMAS() riscv_register_pragmas ()
>
> +/* 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 */
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-14 21:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-14 19:56 [PATCH v2] RISC-V: Implement __clear_cache via __builtin___clear_cache Palmer Dabbelt
2022-10-14 21:59 ` Palmer Dabbelt
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).