在编译器中访问__m128字段 [英] accessing __m128 fields across compilers

查看:166
本文介绍了在编译器中访问__m128字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在 gcc 中可以按索引访问 __ m128 字段,而不使用 union trick。

  __ m128 t; 

float r(t [0] + t [1] + t [2] + t [3]);

我也可以像加载 __ m128 一样一个数组:

  __ m128 t {1.f,2.f,3.f,4.f}; 

这一切都符合 gcc ' s矢量扩展。但是,这些可能在其他地方不可用。加载和访问功能是否支持intel编译器和msvc?

解决方案

加载 __ m128 ,您可以编写GCC,ICC支持的 _mm_setr_ps(1.f,2.f,3.f,4.f) MSVC和clang。

据我所知,clang和最新版本的GCC支持按索引访问 __ m128 字段。我不知道如何在ICC或MSVC中执行此操作。我想 _mm_extract_ps 可以用于所有4种编译器,但它的返回类型很疯狂,使用起来很痛苦。


I've noticed that accessing __m128 fields by index is possible in gcc, without using the union trick.

__m128 t;

float r(t[0] + t[1] + t[2] + t[3]);

I can also load a __m128 just like an array:

__m128 t{1.f, 2.f, 3.f, 4.f};

This is all in line with gcc's vector extensions. These, however, may not be available elsewhere. Are the loading and accessing features supported by the intel compiler and msvc?

解决方案

To load a __m128, you can write _mm_setr_ps(1.f, 2.f, 3.f, 4.f), which is supported by GCC, ICC, MSVC and clang.

So far as I know, clang and recent versions of GCC support accessing __m128 fields by index. I don't know how to do this in ICC or MSVC. I guess _mm_extract_ps works for all 4 compilers but its return type is insane making it painful to use.

这篇关于在编译器中访问__m128字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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