我在阅读一些代码时发现了这一点:
char* FAST_FUNC bb_simplify_path(const char *path)
这里char*
是一个返回类型,但是我不明白FAST_FUNC
的作用。这个FAST_FUNC
在很多地方都有使用。
一般来说,FAST_FUNC
在 busybox 中做什么?
最佳答案
来自include/platform.h
:
/* FAST_FUNC is a qualifier which (possibly) makes function call faster
* and/or smaller by using modified ABI. It is usually only needed
* on non-static, busybox internal functions. Recent versions of gcc
* optimize statics automatically. FAST_FUNC on static is required
* only if you need to match a function pointer's type */
#if __GNUC_PREREQ(3,0) && defined(i386) /* || defined(__x86_64__)? */
/* stdcall makes callee to pop arguments from stack, not caller */
# define FAST_FUNC __attribute__((regparm(3),stdcall))
/* #elif ... - add your favorite arch today! */
#else
# define FAST_FUNC
#endif
基本上,它激活一个依赖于体系结构的函数注释,以加速函数调用。实际的注释取决于平台(因此是 #if
),但在 x86/x86_64(当前此处实现的唯一平台)上,它会激活注释函数上的“stdcall”调用约定。 stdcall
允许将函数的某些参数传递到寄存器而不是堆栈中,从而消除了函数调用调用序列中的一些内存访问。
关于c - FAST_FUNC在busybox中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27286568/