AVX2 8浮子寄存器和洗牌配对寄存器的水平分钟
在8宽SIMD中的Ray VS三角形交叉测试之后,我将在下面的标量中更新T,U和V(求出最低的t和更新t,u,v,如果低于以前的t)。有没有办法在SIMD而不是标量中执行此操作?
int update_tuv(__m256 t, __m256 u, __m256 v, float* t_out, float* u_out, float* v_out)
{
alignas(32) float ts[8];_mm256_store_ps(ts, t);
alignas(32) float us[8];_mm256_store_ps(us, u);
alignas(32) float vs[8];_mm256_store_ps(vs, v);
int min_index{0};
for (int i = 1; i < 8; ++i) {
if (ts[i] < ts[min_index]) {
min_index = i;
}
}
if (ts[min_index] >= *t_out) { return -1; }
*t_out = ts[min_index];
*u_out = us[min_index];
*v_out = vs[min_index];
return min_index;
}
我还没有找到一种解决方案,该解决方案可以找到水平的最小t和缩小/置于沿途的u和v,除了置换和最小测试8次。
After ray vs triangle intersection test in 8 wide simd, I'm left with updating t, u and v which I've done in scalar below (find lowest t and updating t,u,v if lower than previous t). Is there a way to do this in simd instead of scalar?
int update_tuv(__m256 t, __m256 u, __m256 v, float* t_out, float* u_out, float* v_out)
{
alignas(32) float ts[8];_mm256_store_ps(ts, t);
alignas(32) float us[8];_mm256_store_ps(us, u);
alignas(32) float vs[8];_mm256_store_ps(vs, v);
int min_index{0};
for (int i = 1; i < 8; ++i) {
if (ts[i] < ts[min_index]) {
min_index = i;
}
}
if (ts[min_index] >= *t_out) { return -1; }
*t_out = ts[min_index];
*u_out = us[min_index];
*v_out = vs[min_index];
return min_index;
}
I haven't found a solution that finds the horizontal min t and shuffles/permutes it's pairing u and v along the way other than permuting and min testing 8 times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先找到
t
向量的水平最小值。仅此一项就足以通过您的第一个测试拒绝价值。然后找到第一个最小元素的索引,从
u
和v
向量提取并存储该车道。虽然相对简单,并且可能比您当前使用矢量存储的方法更快,然后是标量负载,但如果分支得到充分预测,则上述功能的性能才是很好的。
当该分支是不可预测的(从统计上,导致随机结果)时,完全无分支的实现可能是更好的选择。但是会更复杂,用
_MM_LOAD_SS
加载旧值,用_MM_BLENDV_PS
有条件更新,并使用_MM_STORE_SS
存储回去。First find horizontal minimum of the
t
vector. This alone is enough to reject values with your first test.Then find index of that first minimum element, extract and store that lane from
u
andv
vectors.While relatively straightforward and probably faster than your current method with vector stores followed by scalar loads, the performance of the above function is only great when that
if
branch is well-predicted.When that branch is unpredictable (statistically, results in random outcomes), a completely branchless implementation might be a better fit. Gonna be more complicated though, load old values with
_mm_load_ss
, conditionally update with_mm_blendv_ps
, and store back with_mm_store_ss
.