SSE代码最多查找整数数组

发布于 2025-02-06 13:58:28 字数 817 浏览 1 评论 0原文

我正在努力优化我的C ++代码以写入SSE指令。

我在我们所在的循环上工作。找到最大向量。

void findMax(vector<UInt64> & index)
        auto size = index.size();
        Uint64_t max_val = index[0];
        
       for (size_t i = 1; i < size; ++i)
            max_val = std::max(max_val, index[i]);

}

我正在尝试这种方式:

{
  auto size =  index.size();  

  const auto bytes_sse = sizeof(__m128i);

  const __m128i * data = reinterpret_cast<const __m128i *>(&index);
  __m128i max = reinterpret_cast<const __m128i *>(index[0]);

  const  auto loop_count_sse = (sizeof(index[0])*size)/bytes_sse;

            for(size_t j=0;j<loop_count_sse;j++){
                   max = _mm_max_epi16(max, data+i);
                data += bytes_sse;
            }

但这是不起作用的,请帮助

I am working on optimizing my c++ code to write in to SSE instructions.

I am working on the loop where we are. finding the max of vector.

void findMax(vector<UInt64> & index)
        auto size = index.size();
        Uint64_t max_val = index[0];
        
       for (size_t i = 1; i < size; ++i)
            max_val = std::max(max_val, index[i]);

}

I am trying this way :

{
  auto size =  index.size();  

  const auto bytes_sse = sizeof(__m128i);

  const __m128i * data = reinterpret_cast<const __m128i *>(&index);
  __m128i max = reinterpret_cast<const __m128i *>(index[0]);

  const  auto loop_count_sse = (sizeof(index[0])*size)/bytes_sse;

            for(size_t j=0;j<loop_count_sse;j++){
                   max = _mm_max_epi16(max, data+i);
                data += bytes_sse;
            }

but this is not working,Please help

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文