[PATCH] Inline mempcpy

Wilco Dijkstra wdijkstr@arm.com
Mon May 18 19:56:00 GMT 2015


> Joseph Myers wrote:
> On Mon, 18 May 2015, Wilco Dijkstra wrote:
> 
> > #if defined __USE_GNU && !defined TARGET_HAS_OPTIMIZED_MEMPCPY
> 
> TARGET_HAS_OPTIMIZED_MEMPCPY is in the user's namespace.  Use the existing
> _HAVE_STRING_ARCH_mempcpy (or something like that in the implementation
> namespace, anyway, defined based on consensus for each architecture).
>
> > #undef mempcpy
> > #undef __mempcpy
> > #define mempcpy(dest, src, n) __mempcpy_inline(dest, src, n)
> > #define __mempcpy(dest, src, n) __mempcpy_inline(dest, src, n)
> 
> Bad formatting of function calls.
> 
> > __attribute__((__always_inline__)) inline void *
> 
> __extern_always_inline (and you need to condition things on defined
> __extern_always_inline, and I'm not sure it this will reliably work with
> GCC versions predating the always_inline attribute, or if you need
> __GNUC_PREREQ (3,2) as well ... maybe the __extern_always_inline
> definition should be conditional on that).  I'm also doubtful of using
> such inlines when not optimizing.

OK, so we only inline with __OPTIMIZE__ and __extern_always_inline defined
(this limits inlining to modern GCCs but that's not an issue).

We also need to check _FORCE_INLINES to ensure string/string-inlines.c doesn't
report errors. So:


#if defined __USE_GNU && defined __OPTIMIZE__ && defined __extern_always_inline
# if !defined _FORCE_INLINES && !defined _HAVE_STRING_ARCH_mempcpy

#undef mempcpy
#undef __mempcpy
#define mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)
#define __mempcpy(dest, src, n) __mempcpy_inline (dest, src, n)

__extern_always_inline void *
__mempcpy_inline (void *__restrict __dest,
                  const void *__restrict __src, size_t __n)
{
  return (char *) memcpy (__dest, __src, __n) + __n;
}

# endif
#endif

Wilco




More information about the Libc-alpha mailing list