使用 SSE 内联函数的寄存器短缺
Register's shortage using SSE intrinsics
在这个SSE加载/存储后的内存事务中,我询问了显式寄存器内存事务和中间指针之间的差异。在实践中,中间指针显示出略高的性能,然而,就硬件而言,什么是中间指针还不清楚?如果创建了指针,是否意味着某些寄存器也被占用,或者寄存器的调用发生在某些SSE操作期间(例如_mm_mul)?
让我们考虑一下这个例子:
struct sse_simple
{
sse_simple(unsigned int InputLength):
Len(InputLength/4),
input1((float*)_mm_malloc((float *)_mm_malloc(cast_sz*sizeof(float), 16))),
input2((float*)_mm_malloc((float *)_mm_malloc(cast_sz*sizeof(float), 16))),
output((float*)_mm_malloc((float *)_mm_malloc(cast_sz*sizeof(float), 16))),
inp1_sse(reinterpret_cast<__m128*>(input1)),
inp1_sse(reinterpret_cast<__m128*>(input2)),
output_sse(reinterpret_cast<__m128*>(output))
{}
~sse_simple()
{
_mm_free(input1);
_mm_free(input2);
_mm_free(output);
}
void func()
{
for(auto i=0; i<Len; ++i)
output_sse[i] = _mm_mul(inp1_sse[i], inp2_sse[i]);
}
float *input1;
float *input2;
float *output;
__m128 *inp1_sse;
__m128 *inp2_sse;
__m128 *output_sse;
unsigned int Len;
};
在上面的例子中,中间指针inp1_sse、inp2_sse和output_sse在构造函数中创建一次。如果我复制大量的sse_simple对象(例如50000或更多),这会导致寄存器短缺吗?
首先,寄存器是靠近计算单元的小型存储器(意味着访问速度非常快)。编译器尽可能多地使用它们来加快计算速度,但如果不能,它就会使用内存。由于寄存器中存储的内存量很小,所以在计算过程中,寄存器通常只用作临时寄存器。大多数时候,除了循环索引等临时变量外,所有内容都会存储在内存中。。。所以寄存器的不足只会减慢计算速度。
在计算过程中,指针存储在通用寄存器(GPR)中,无论它们指向浮点、向量还是其他什么,而向量__m128
存储在特定寄存器中。
因此,在您的示例中,树数组将存储在内存和行中
output_sse[i] = _mm_mul(inp1_sse[i], inp2_sse[i]);
编译为:
movaps -0x30(%rbp),%xmm0 # load inp1_sse[i] in register %xmm0
movaps -0x20(%rbp),%xmm1 # load inp2_sse[i] in register %xmm1
mulps %xmm1,%xmm0 # perform the multiplication the result is stored in %xmm0
movaps %xmm0,(%rdx) # store the result in memory
正如您所看到的,指针是使用寄存器%rbp
和%rdx
存储的。
相关文章:
- 本质:使用__128寄存器
- 将寄存器设计成可由C和C++访问的外设的最佳实践
- 在模拟器中使用并集来模拟CPU寄存器有多合适
- 使用英特尔 PIN 修改寄存器
- 除非使用某些寄存器,否则函数挂钩会崩溃
- "变量":函数中函数作用域不允许初始化的自动或寄存器变量'naked'
- 如何在程序集函数中将元素数组作为参数传递时转发 ARM 寄存器的地址指针
- 视觉 C++编译器在计算其参数之前是否允许将函数 ptr 存储在寄存器中?
- 汇编函数调用是否会导致所有寄存器被推送到堆栈中
- 函数返回布尔值,只设置整个寄存器的1个字节
- 链路寄存器 (LR) 是否受内联函数或裸函数的影响
- 如何在使用高达 SSSE3 的内部函数后存储 16 字节寄存器中的 4 个字节
- std::函数回调,参数采用观察者模式(寄存器主题上的占位符)
- 使用 SSE 内联函数的寄存器短缺
- 将函数标记为脏(指定调用方应保存所有寄存器)
- 当使用SIMD内部函数时,如何在寄存器中保留与输入相关的热数据
- C++(嵌套)函数调用指令-寄存器
- C函数来尽可能多地使用寄存器
- 如何使用 Visual C++ 中的 Delphi 寄存器调用约定调用函数?
- 函数调用后寄存器的状态是什么