AVX除以__M256I将32位整数挤满了两个(无AVX2)

发布于 2025-01-25 10:20:10 字数 388 浏览 3 评论 0原文

我正在寻找最快的方法,将包装的32位整数的__ M256i除以两个(又称一个换档)使用AVX。我无法访问AVX2。 据我所知,我的选择是:

  1. 下载到
  2. 用于签名的32位元素的AVX __M256I整数部门

如果我需要下去SSE2,我会感谢最佳的SSE2实施。 如果是2),我想知道要使用的内在信息,以及是否有更优化的实现来专门除以2。 谢谢!

I'm looking for the fastest way to divide an __m256i of packed 32-bit integers by two (aka shift right by one) using AVX. I don't have access to AVX2.
As far as I know, my options are:

  1. Drop down to SSE2
  2. Something like AVX __m256i integer division for signed 32-bit elements

In case I need to go down to SSE2 I'd appreciate the best SSE2 implementation.
In case it's 2), I'd like to know the intrinsics to use and also if there's a more optimized implementation for specifically dividing by 2.
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简美 2025-02-01 10:20:10

假设您知道自己在做什么,这就是该功能。

inline __m256i div2_epi32( __m256i vec )
{
    // Split the 32-byte vector into 16-byte ones
    __m128i low = _mm256_castsi256_si128( vec );
    __m128i high = _mm256_extractf128_si256( vec, 1 );
    // Shift the lanes within each piece; replace with _mm_srli_epi32 for unsigned version
    low = _mm_srai_epi32( low, 1 );
    high = _mm_srai_epi32( high, 1 );
    // Combine back into 32-byte vector
    vec = _mm256_castsi128_si256( low );
    return _mm256_insertf128_si256( vec, high, 1 );
}

但是,这样做不一定比处理16个字节向量更快。在大多数CPU上,除了AMD ZEN 1 CPU外,这些插入/提取说明的性能并不是很棒。

Assuming you know what you’re doing, here’s that function.

inline __m256i div2_epi32( __m256i vec )
{
    // Split the 32-byte vector into 16-byte ones
    __m128i low = _mm256_castsi256_si128( vec );
    __m128i high = _mm256_extractf128_si256( vec, 1 );
    // Shift the lanes within each piece; replace with _mm_srli_epi32 for unsigned version
    low = _mm_srai_epi32( low, 1 );
    high = _mm_srai_epi32( high, 1 );
    // Combine back into 32-byte vector
    vec = _mm256_castsi128_si256( low );
    return _mm256_insertf128_si256( vec, high, 1 );
}

However, doing that is not necessarily faster than dealing with 16-byte vectors. On most CPUs, the performance of these insert/extract instructions ain’t great, except maybe AMD Zen 1 CPU.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文