我正在用C语言编写一个需要进行快速数学计算的程序.我正在使用内联SSE汇编指令来获取一些SIMD操作(使用压缩的双精度浮点数).我在Linux上使用GCC进行编译.
我处在需要循环某些数据的情况下,我在计算中使用了一个常数因子.我想在循环期间将这个因素隐藏在一个安全的寄存器中,所以我不必每次都重新加载它.
用一些代码澄清:
struct vect2 {
fltpt x;
fltpt y;
}__attribute__((aligned(16))); /* Align on 16B boundary for SSE2 instructions */
typedef struct vect2 vect2_t;
void function()
{
/* get a specific value set up in xmm1, and keep it there for the
* rest of the loop. */
for( int i = 0, i<N; i++ ){
asm(
"Some calculations;"
"on an element of;"
"a data set.;"
"The value in xmm1;"
"is needed;"
);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用"register"关键字做一些事情.但是,如果我没有弄错,看起来我只能保留指向该结构的指针(在通用寄存器中).这需要每次迭代都要尊重,浪费宝贵的时间. …