嗨,我在优化方面有一些问题。
我试着用内置的函数编写了gcc测试:
#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我试着用以下两种方法编译它:
1路:
gcc -mglibc -O -ffast-math -std=c99 -fno-ident -S -o builtins-58.s
在输出汇编程序文件中,所有call pow都更改为call cbrt --它的预期。
2路:
gcc -mbionic -O -ffast-math -std=c99 -fno-ident -S -o builtins-58.s
通过使用-mbionic而不是-mglibc,我得到了call pow的输出
有人知道optmimization for builtin函数是如何在Bionic中工作的吗?
发布于 2012-11-23 05:27:36
之所以发生这种情况,是因为在gcc 4.7中,我们在builins.def文件中进行了特殊检查(检查是否为builins.def),其中定义了所有内置函数。
在另一个文件中:define TARGET_C99_FUNCTIONS (OPTION_GLIBC)
这些检查检查库,如果没有glibc,那么我们就没有cbrt函数。因此,我们不能将pow转换为cbrt,这是根本原因。
https://stackoverflow.com/questions/13397512
复制相似问题