tags:

views:

43

answers:

1

Hi,

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;
}

What point I'm missing?

A little help will be appreciated, thanks.

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

+1  A: 

You should be able to use _MM_EXTRACT_FLOAT.

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.

Paul R
I thought that too.
Tony Alexander Hild
I guess it's down to the way that Intel describe the instruction in their documentation, which may or may not be an error - the gcc headers just implement what is there in the documentation.
Paul R