访问Visual Studio与Xcode中__M128D内在的组件不以相同的方式工作吗?

发布于 2025-01-31 07:43:08 字数 289 浏览 1 评论 0原文

以下代码与Xcode合作:

const __m128d source      = { x, y };
const double  destination = source[0];    // Read the "x" from "source"

在Visual Studio的最新版本中,我从编译器中获取以下错误消息: --->没有操作器与这些操作数匹配。

根据我从Web中发现的所有示例,上面应该是访问__M128D内部这些组件的标准方法,那么什么导致错误以及如何解决该组件?

The below code works fine with Xcode:

const __m128d source      = { x, y };
const double  destination = source[0];    // Read the "x" from "source"

In latest version of Visual Studio I get the following error message from the compiler:
---> No operator "[]" matches these operands.

According to all examples I've found from the web the above should be the standard way of accessing those components inside __m128d, so what is causing the error and how to fix it?

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

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

发布评论

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

评论(1

黎歌 2025-02-07 07:43:08

source [i]语法是GCC/clang扩展名,不适用于MSVC。

要提取A __ M128D向量组件的下部组件,

double lower = _mm_cvtsd_f64(source);

用于上部组件,您需要首先将其移至下部,例如,例如,使用:

double higher = _mm_cvtsd_f64( // extract value
                  _mm_castps_pd( // reinterpret as __m128d
                    _mm_movehl_ps( // move high half of second argument to lower half
                      _mm_setzero_ps(), // could be an arbitrary vector 
                      _mm_castpd_ps(source)
                ) ) );

而不是_movehl_ps您还可以使用_mm_shuffle_pd指令。
另外,如果您实际上打算将上层元素存储到内存中,则可以使用:

double dest;   // target somewhere in memory
_mm_storeh_pd(&dest, source);

The source[i] syntax is a GCC/Clang extension which does not work with MSVC.

To extract the lower double component of a __m128d vector use

double lower = _mm_cvtsd_f64(source);

For the upper component, you need to first move it to the lower part, e.g., using:

double higher = _mm_cvtsd_f64( // extract value
                  _mm_castps_pd( // reinterpret as __m128d
                    _mm_movehl_ps( // move high half of second argument to lower half
                      _mm_setzero_ps(), // could be an arbitrary vector 
                      _mm_castpd_ps(source)
                ) ) );

Instead of _movehl_ps you could also use a _mm_shuffle_pd instruction.
Also, if you actually intend to store the upper element to memory, you could use:

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