暗含SIMD(SSE / AVX)与GCC广播 [英] implict SIMD (SSE/AVX) broadcasts with GCC
问题描述
我已经设法将大部分SIMD代码转换为GCC的向量扩展。但是,我还没有找到一个很好的解决方案,如下所示: );
我想要做的是
pre > __ m256 argeg0 = a [i];
如果您在我设法获得了与另一个SIMD寄存器一起工作的广播。以下工作:
__ m256 x,y;
y = x + 3.14159f; //广播x + 3.14159
y = 3.14159f * x; //广播3.14159 * x
但这不起作用:
__m256 x;
x = 3.14159f; //应广播3.14159,但不起作用
我如何使用GCC做到这一点?
我认为目前没有直接的方法,您必须使用您已经注意到的语法来解决它:
__ m256 zero = {};
__m256 x =零+ 3.14159f;
如果我们能够就一个好的语法达成一致,未来可能会发生变化,请参阅 PR 55726 。
注如果你想用一个非常量 float s
{s,s,... s} >,上面的技巧只适用于整数,或浮动和 -fno-signed-zeros
。你可以将它调整为 __ m256 x = s-zero;
,除非你使用 -frounding-math
,否则它会起作用。 Z boson建议的最后一个版本是 __ m256 x =(zero + 1.f)* s;
它应该在大多数情况下工作(除了编译器偏执sNaN)。
I have manged to convert most of my SIMD code to us the vector extensions of GCC. However, I have not found a good solution for doing a broadcast as follows
__m256 areg0 = _mm256_broadcast_ss(&a[i]);
I want to do
__m256 argeg0 = a[i];
If you see my answer at Mutiplying vector by constant using SSE I managed to get broadcasts working with another SIMD register. The following works:
__m256 x,y;
y = x + 3.14159f; // broadcast x + 3.14159
y = 3.14159f*x; // broadcast 3.14159*x
but this won't work:
__m256 x;
x = 3.14159f; //should broadcast 3.14159 but does not work
How can I do this with GCC?
I think there is currently no direct way and you have to work around it using the syntax you already noticed:
__m256 zero={};
__m256 x=zero+3.14159f;
It may change in the future if we can agree on a good syntax, see PR 55726.
Note that if you want to create a vector { s, s, ... s }
with a non-constant float s
, the technique above only works with integers, or with floats and -fno-signed-zeros
. You can tweak it to __m256 x=s-zero;
and it will work unless you use -frounding-math
. A last version, suggested by Z boson, is __m256 x=(zero+1.f)*s;
which should work in most cases (except possibly with a compiler paranoid about sNaN).
这篇关于暗含SIMD(SSE / AVX)与GCC广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!