使用SIMD恒定浮点 [英] Constant floats with SIMD

查看:134
本文介绍了使用SIMD恒定浮点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试优化一些使用Microsoft的sse内在函数的代码.优化代码时最大的问题之一是LHS,它在我想使用常量时发生.在生成某些常量方面似乎有些信息(此处此处-13.4节),但全部是汇编程序(我宁愿避免).

I've been trying my hand at optimising some code I have using microsoft's sse intrinsics. One of the biggest problems when optimising my code is the LHS that happens whenever I want to use a constant. There seems to be some info on generating certain constants (here and here - section 13.4), but its all assembly (which I would rather avoid).

问题是当我尝试使用内在函数实现同一件事时,msvc抱怨不兼容的类型等.有人知道使用内在函数的等效技巧吗?

The problem is when I try to implement the same thing with intrinsics, msvc complains about incompatible types etc. Does anyone know of any equivalent tricks using intrinsics?

示例-生成{1.0,1.0,1.0,1.0}

Example - Generate {1.0,1.0,1.0,1.0}

//pcmpeqw xmm0,xmm0 
__m128 t = _mm_cmpeq_epi16( t, t );

//pslld xmm0,25 
_mm_slli_epi32(t, 25);

//psrld xmm0,2
return _mm_srli_epi32(t, 2);

这会产生一堆有关不兼容类型(__m128与_m128i)的错误.我对此很陌生,因此可以肯定我缺少明显的东西.有人可以帮忙吗?

This generates a bunch of errors about incompatible type (__m128 vs _m128i). I'm pretty new to this, so I'm pretty sure I'm missing something obvious. Can anyone help?

tldr -如何生成填充有ms内在函数的单精度常量浮点数的__m128 vec?

tldr - How do I generate an __m128 vec filled with single precision constant floats with ms intrinsics?

感谢您的阅读:)

推荐答案

使用 _ mm_castsi128_ps .另外,第二行应该是

Simply cast __m128i to __m128 using _mm_castsi128_ps. Also, the second line should be

t = _mm_slli_epi32(t, 25)

这篇关于使用SIMD恒定浮点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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