0

I am newbie to sse, and I have trouble to find it, please tell me what is the good way to convert (truncate as in "(int) float_") four packed floats I have in xmm3 register into four ints and store it into memory (some like "movaps oword [edx+32], xmm3 " storing is clear but i do not find just how to convert)

grunge fightr
  • 1,360
  • 2
  • 19
  • 38
  • You can save yourself a lot of grief by using intrinsics rather than trying to do this in raw asm. – Paul R Apr 17 '13 at 08:05

1 Answers1

3

Use intrinsics if you value your sanity (and free time):

int32_t *dest;
__m128 vf = _mm_set_ps(4.0f, 3.0f, 2.0f, 1.0f);
__m128i vi = _mm_cvttps_epi32(vf); // 4 x float -> 4 x int (with truncation)
_mm_store_epi32(dest, vi); // NB: use _mm_storeu_epi32 if `dest` not aligned

If you must use asm for some reason the the corresponding instruction for _mm_cvttps_epi32 is cvttps2dq.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • alrrite `cvtps2dq xmm3, xmm3` worked, (i thoud there is no such thing (somewhat lost in sse mnemonics) but there it is) – grunge fightr Apr 17 '13 at 09:39
  • 1
    Get the AVX intrinsics guide form Intel's AVX page - it has all the SSE intrinsics and instructions (as well as AVX of course) in a nice summary format in a standalone utility for Linux/Windows/Mac. – Paul R Apr 17 '13 at 09:59