SSE 数据类型和原语

发布于 2024-11-28 12:47:56 字数 251 浏览 4 评论 0原文

在网络上的大多数教程或代码片段中,人们会看到以下内容:

float *arr= (float*) _aligned_malloc(length * sizeof(float), 16);
__m128 *m1 = (__m128*)arr;

这是否违反了严格的别名规则?我认为确实如此,但肯定所有这些教程作者都不会为了方便而忽略它,因为 __m128 是一个包含 float[4] 的联合,也许我误解了它的一些复杂部分。

In most tutorials or code snippets on the net one sees the following:

float *arr= (float*) _aligned_malloc(length * sizeof(float), 16);
__m128 *m1 = (__m128*)arr;

Does this violate strict aliasing rules or not? I'd think it does, but then surely all those tutorial writers don't ignore it just for convenience and since __m128 is a union containing float[4] maybe I misunderstand some intricate parts about it.

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

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

发布评论

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

评论(2

泛泛之交 2024-12-05 12:47:56

但这还没有违反它。然而,通过一个指针写入并通过另一个指针读取将违反严格的别名。

相反,您应该使用如下函数:

That hasn't violated it -- yet. However, writing through one pointer and reading through the other would violate strict aliasing.

Instead, you should use functions like:

始终不够 2024-12-05 12:47:56

这是 GCC 的编译器特定答案

GCC 的 xmmintrin 标头4.4.3 定义了以下内容:

typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));

所以,是的,您违反了严格别名,但您可以这样做那种类型。奇怪的是,__v4sf 类型没有标记为__may_alias__,因此不能以这种方式使用。

This is a compiler specific answer for GCC

The xmmintrin header for GCC 4.4.3 defines the following:

typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));

So, yes, you violate strict aliasing, but you are allowed to do so with that type. Oddly, the __v4sf type is not marked as __may_alias__, so it cannot be used in this manner.

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