I would like to compare the GCC memcpy built-in function compared to one of libc. However, all iterations of -fno-builtin or -fno-builtin-memcpy seem ignored.
//g++ -O3 foo.cpp -S or //g++ -O3 -fno-builtin foo.cpp -S #include <string.h> int main() { volatile int n = 1000; //int n = 1000; float *x = new float[1000]; float *y = new float[1000]; memcpy(y,x,sizeof(float)*n); //__builtin_memcpy(y,x,sizeof(float)*n); }
I found that if n in the source code is not mutable, then it is embedded in the embedded code. However, when n becomes volatile, it calls the __memcpy_chk function, which is a memcpy version with a buffer overflow check . If n is volatile, and instead I call __builtin_memcpy , then it calls memcpy .
So my conclusion is that inline code is only generated when n is known at compile time and that -fno-builtin useless. I am using GCC 4.8.2.
Is -fno-builtin deprecated? Is there a way to make a GCC memcpy call from the C library, even when n known at compile time?
source share