如何使用_mm_extract_ps SSE GCC instrinc函数将十六进制浮点数转换为C / C ++中的浮点数 [英] How to convert a hex float to a float in C/C++ using _mm_extract_ps SSE GCC instrinc function

查看:948
本文介绍了如何使用_mm_extract_ps SSE GCC instrinc函数将十六进制浮点数转换为C / C ++中的浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个SSE代码到2D卷积,但SSE文档非常稀疏。
我使用_mm_dp_ps计算点积,使用_mm_extract_ps得到点积结果,但_mm_extract_ps返回一个表示浮点数的十六进制,我不知道如何将这个十六进制浮点数转换为常规浮点数。我可以使用__builtin_ia32_vec_ext_v4sf返回一个float,但我想保持与其他编译器的兼容性。

I'm writing a SSE code to 2D convolution but SSE documentation is very sparse. I'm calculating dot product with _mm_dp_ps and using _mm_extract_ps to get the dot product result, but _mm_extract_ps returns a hex that represents a float and I can't figure out how to convert this hex float to a regular float. I could use __builtin_ia32_vec_ext_v4sf that returns a float but I wanna keep compatibility with others compilers.

_mm_extract_ps (__m128 __X, const int __N)
{
  union { int i; float f; } __tmp;
  __tmp.f = __builtin_ia32_vec_ext_v4sf ((__v4sf)__X, __N);
  return __tmp.i;
}

我错过了什么?

感谢您的帮助。

OpenSUSE 11.2

GCC 4.4.1

C ++

编译器选项

-fopenmp -Wall -O3 -msse4.1 -march = core2

链接器选项

-lgomp -Wall -O3 -msse4.1 -march = core2

OpenSUSE 11.2
GCC 4.4.1
C++
Compiler options
-fopenmp -Wall -O3 -msse4.1 -march=core2
Linker options
-lgomp -Wall -O3 -msse4.1 -march=core2

推荐答案

使用 _MM_EXTRACT_FLOAT

顺便说一下,看起来好像 _mm_extract_ps _MM_EXTRACT_FLOAT 应该是相反的,即 _mm_extract_ps 应该返回一个浮点和 _MM_EXTRACT_FLOAT 应该返回int表示,但是我知道什么。

Incidentally it looks to me as if _mm_extract_ps and _MM_EXTRACT_FLOAT should be the other way around, i.e. _mm_extract_ps should return a float and _MM_EXTRACT_FLOAT should return the int representation, but what do I know.

这篇关于如何使用_mm_extract_ps SSE GCC instrinc函数将十六进制浮点数转换为C / C ++中的浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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