Question

Hi i have some problems with optimization.
I tried to compile one of gcc test with builtin functions:

#include <stdio.h>

#ifdef HAVE_C99_RUNTIME
double test1 (double x)
{
  return __builtin_pow (x, 1/3);
}

double test2 (double x)
{
  return __builtin_pow (x, 4./3.);
}

double test3a (double x)
{
  return __builtin_pow (x, 5./3.);
}

double test3b (double x)
{
  return __builtin_pow (x, -5./3.);
}

double test4 (double x)
{
  return __builtin_pow (x, 7./3.);
}
#endif

I tried to compile it with next 2 ways:
1 way:
gcc -mglibc -O -ffast-math -std=c99 -fno-ident -S -o builtins-58.s
And in output assembler file all call pow was changed to call cbrt - its expected

2 way:
gcc -mbionic -O -ffast-math -std=c99 -fno-ident -S -o builtins-58.s
With using -mbionic instead of-mglibc i got output with call pow

Does anybody know how optmimization for builtin functions works in Bionic

Was it helpful?

Solution

It's happens becuse of in gcc 4.7 we have special check (check for TARGET_C99_FUNCTIONS) in builins.def file, where is defined all builtin function.

And in another file we have: define TARGET_C99_FUNCTIONS (OPTION_GLIBC)

These check checks library, and if there no glibc then we don't have cbrt function. So we cant transform pow to cbrt and it's the root cause.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top