Skip to content

Commit

Permalink
sh: Use GCC __builtin_prefetch() to implement prefetch().
Browse files Browse the repository at this point in the history
GCC's __builtin_prefetch() was introduced a long time ago, all
supported GCC versions have it. So this patch is to use it for
implementing the prefetch on SH2A and SH4.

The current  prefetch implementation is almost equivalent with
__builtin_prefetch.
The third parameter in the __builtin_prefetch is the locality
that it's not supported on SH architectures.  It has been set
to three and it should be verified if it's suitable for SH2A
as well. I didn't test on this architecture.

The builtin usage should be more efficient that an __asm__
because less barriers, and because the compiler doesn't see the
inst as a "black box" allowing better code generation.

This has been already done on other architectures (see the commit:
0453fb3).

Many thanks to Christian Bruel <christain.bruel@st.com> for his
support on evaluate the impact of the gcc built-in on SH4 arch.

No regressions found while testing with LMbench on STLinux targets.

Signed-off-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Signed-off-by: Stuart Menefy <stuart.menefy@st.com>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
  • Loading branch information
Giuseppe CAVALLARO authored and Paul Mundt committed Nov 18, 2010
1 parent 94ab115 commit d53e430
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions arch/sh/include/asm/processor_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ extern unsigned long get_wchan(struct task_struct *p);
#define ARCH_HAS_PREFETCHW
static inline void prefetch(void *x)
{
__asm__ __volatile__ ("pref @%0\n\t" : : "r" (x) : "memory");
__builtin_prefetch(x, 0, 3);
}

#define prefetchw(x) prefetch(x)
static inline void prefetchw(void *x)
{
__builtin_prefetch(x, 1, 3);
}
#endif

#endif /* __KERNEL__ */
Expand Down

0 comments on commit d53e430

Please sign in to comment.