什么是加载和从128位SSE矢量抽取32位整数值的最有效方法是什么? [英] What's the most efficient way to load and extract 32 bit integer values from a 128 bit SSE vector?

查看:212
本文介绍了什么是加载和从128位SSE矢量抽取32位整数值的最有效方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用最优化上证所内部函数我的code,但我遇到了一个问题,我不知道一个好办法,从矢量提取整数值我已经做了上证所内部函数操作后,得到我想要的东西。

I'm trying to optimize my code using SSE intrinsics but am running into a problem where I don't know of a good way to extract the integer values from a vector after I've done the SSE intrinsics operations to get what I want.

有谁知道一个好办法做到这一点?我在编程的C和我的编译器是gcc 4.3.2版。

Does anyone know of a good way to do this? I'm programming in C and my compiler is gcc version 4.3.2.

感谢您的帮助。

推荐答案

这要看你可以假设一下SSE支持的最低水平,你所拥有的。

It depends on what you can assume about the minimum level of SSE support that you have.

让我们回到SSE2一路有 _mm_extract_epi16 PEXTRW ),它可以用来提取任何16从128位的向量位元件。则需要两次调用此得到一个32位的元件的两个半部

Going all the way back to SSE2 you have _mm_extract_epi16 (PEXTRW) which can be used to extract any 16 bit element from a 128 bit vector. You would need to call this twice to get the two halves of a 32 bit element.

在最近的SSE版本(SSE4.1和更高版本),你有 _mm_extract_epi32 PEXTRD ),它可以在一个指令中提取一个32位的元素

In more recent versions of SSE (SSE4.1 and later) you have _mm_extract_epi32 (PEXTRD) which can extract a 32 bit element in one instruction.

另外,如果这不是一个性能关键循环中你可以使用一个联盟,例如

Alternatively if this is not inside a performance-critical loop you can just use a union, e.g.

typedef union
{
    __m128i v;
    int32_t a[4];
} U32;

这篇关于什么是加载和从128位SSE矢量抽取32位整数值的最有效方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆