Re: C++: Difference between calling memcpy and __builtin_memcpy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/15/2016 03:21 AM, Martin Sebor wrote:
> On 02/12/2016 04:55 AM, Florian Weimer wrote:
>> For the C++ compilers version which recognize memcpy, is there a
>> difference between calling memcpy via your own extern "C" declaration,
>> and calling __builtin_memcpy?
> 
> Except in freestanding mode (with builtins disabled) I don't believe
> there is a difference.  They both get expanded the same way (either
> inline or to a call to memcpy depending on arguments).

Hmm.  I tried to verify this using:

#include <stddef.h>

extern "C" size_t strlen(const char*);
extern "C" char *strchr(const char *, char);
const char *search(const char *, int) __asm__ ("strchr");

size_t
call_strchr_0 (char *s)
{
  return strlen(strchr(s, 0));
}

size_t
call_strchr_1 (char *s)
{
  extern char *strchr(char *, char);
  return strlen(strchr(s, 0));
}

size_t
call_strchr_2 (const char *s)
{
  extern const char *strchr(const char *, char);
  return strlen(strchr(s, 0));
}

size_t
call_search (const char *s)
{
  return strlen(search(s, 0));
}

size_t
call_builtin (const char *s)
{
  return strlen(__builtin_strchr(s, 0));
}


Only the last call in call_builtin is optimized with the knowledge of
the meaning of the strchr function.

I'm trying to determine what to use as the best possible fix for this
glibc bug:

  https://sourceware.org/bugzilla/show_bug.cgi?id=19618

I'm wondering if I should switch to a __builtin-based approach for GCC,
and the extern hack for non-GCC compilers.

Florian



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux