使用内部函数时出现未处理的异常

发布于 2024-10-27 00:39:07 字数 402 浏览 1 评论 0原文

我有一个使用 VC++ 创建的应用程序,想要通过向量化一些操作来探索优化机会。

首先,我正在尝试以下代码:

__m128i p1;

p1.m128i_u32[0] = 1;
p1.m128i_u32[1] = 2;
p1.m128i_u32[2] = 3;
p1.m128i_u32[3] = 4;

__m128i p2;

p2.m128i_u32[0] = 1;
p2.m128i_u32[1] = 2;
p2.m128i_u32[2] = 3;
p2.m128i_u32[3] = 4;

__m128i res2= _mm_mul_epi32(p1,p2);

但是,当执行 _mm_mul_epi32 时,我收到未处理的异常或非法操作错误,我不知道为什么会发生。 有人可以告诉我出了什么问题吗?

I have an application created using VC++, and wanted to explore optimization opprtunity by vectorizing some operations.

To begin with, I am trying the following code :

__m128i p1;

p1.m128i_u32[0] = 1;
p1.m128i_u32[1] = 2;
p1.m128i_u32[2] = 3;
p1.m128i_u32[3] = 4;

__m128i p2;

p2.m128i_u32[0] = 1;
p2.m128i_u32[1] = 2;
p2.m128i_u32[2] = 3;
p2.m128i_u32[3] = 4;

__m128i res2= _mm_mul_epi32(p1,p2);

However, I am getting unhandled exception or illegal operation error when _mm_mul_epi32 is executed, I have no clue why it occurs.
Can someone please tell what is wrong?

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

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

发布评论

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

评论(2

风追烟花雨 2024-11-03 00:39:07

_mm_mul_epi32 映射到 PMULDQ 指令,该指令仅在 SSE4 和 AVX 中可用。您需要有一个相当新的 Intel CPU 才能拥有 SSE4 或 AVX,例如 Nehalem、Sandy Bridge(Core i5、i7)。

另请注意,您可能会发现使用内在函数来初始化 SIMD 向量更容易、更简洁,例如

__m128i p1 = _mm_set_epi32(1, 2, 3, 4);
__m128i p2 = _mm_set_epi32(1, 2, 3, 4);
__m128i res2 = _mm_mul_epi32(p1, p2);

_mm_mul_epi32 maps to the PMULDQ instruction, which is only available in SSE4 and AVX. You need to have a reasonably recent Intel CPU in order to have SSE4 or AVX, e.g. Nehalem, Sandy Bridge (Core i5, i7).

Note also that you might find it easier and more succinct to use intrinsics to initialise SIMD vectors, e.g.

__m128i p1 = _mm_set_epi32(1, 2, 3, 4);
__m128i p2 = _mm_set_epi32(1, 2, 3, 4);
__m128i res2 = _mm_mul_epi32(p1, p2);
素手挽清风 2024-11-03 00:39:07

您不应该使用成员 m128i_i32 而不是 m128i_u32 吗?

该指令将两组 32 位有符号整数相乘。

来自 MSDN

如果您确实需要m128i_u32,那么您必须使用_mm_mul_epu32()

Shouldn't you be using the member m128i_i32 instead of m128i_u32 ?

This instruction multiplies two sets of 32-bit signed integers.

From MSDN.

If you really need m128i_u32 then you must use _mm_mul_epu32() instead.

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