我正在制作一个向量/矩阵库。(GCC、ARM NEON、iPhone)
typedef struct{ float v[4]; } Vector;
typedef struct{ Vector v[4]; } Matrix;
我将结构数据作为指针传递,以避免调用函数时数据复制导致性能下降。所以我一开始设计了这样的功能:
void makeTranslation(const Vector* factor, Matrix* restrict result);
但是,如果函数是内联的,是否有任何理由将值作为指针传递以提高性能?这些变量也被复制了吗?寄存器和缓存怎么样?我试图重新设计这样的功能:
inline Matrix makeTranslation(const Vector factor) __attribute__ ((always_inline));
您如何看待每个案例的通话费用?
- 我在第二个签名中添加了“const”以反映建议。