Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SIMD and difference between packed and scalar double precision

Tags:

I am reading Intel's intrinsics guide while implementing SIMD support. I have a few confusions and my questions are as below.

  1. __m128 _mm_cmpeq_ps (__m128 a, __m128 b) documentation says it is used to compare packed single precision floating points. What does "packed" mean? Do I need to pack my float values somehow before I can use them?

  2. For double precision there are intrinsics like _mm_cmpeq_sd which means compare the "lower" double precision floating point elements. What does lower and upper double precision elemtns mean? Can I use them to compare a vector of C++ double type elements or not? Or do I need to process them in some way before I compare them?

like image 607
user1461001 Avatar asked Apr 25 '13 15:04

user1461001


People also ask

What is a packed float?

In this context, "packed" means "several of the same type put into one lump" - so "packed single precision floating point" means 4 * 32 bit floating point numbers stored as a 128-bit value.

What means double precision?

Double precision means the numbers takes twice the word-length to store. On a 32-bit processor, the words are all 32 bits, so doubles are 64 bits. What this means in terms of performance is that operations on double precision numbers take a little longer to execute.

What is double precision floating point representation?

Double-precision floating-point format (sometimes called FP64 or float64) is a computer number format, usually occupying 64 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.


2 Answers

In SSE, the 128 bits registers can be represented as 4 elements of 32 bits or 2 elements of 64 bits.

SSE defines two types of operations; scalar and packed. Scalar operation only operates on the least-significant data element (bit 0~31 or 0~63), and packed operation computes all elements in parallel.

_mm_cmpeq_sd is designed to work with double-precision (64-bit) floating-point elements and would only compare the least-significant data element (first 64 bits) of the two operands (scalar).

_mm_cmpeq_pd is designed to work with double-precision (64-bit) floating-point elements as well but would compare each two groups of 64 bits in parallel (packed).

_mm_cmpeq_ss is designed to work with single-precision (32-bit) floating-point elements and would only compare the least-significant data element (first 32 bits) of the two operands (scalar).

_mm_cmpeq_ps is designed to work with single-precision (32-bit) floating-point elements and would compare each group of 32 bits in parallel (packed).

If you're using 32 bits float, you could pack the float in quadruplet to make use of the 128 bits space. That way, _mm_cmpeq_ps would be able to make 4 comparison in parallel.

If you're using 64 bits double, you could pack the double in pair to make use of the 128 bits space. That way, _mm_cmpeq_pd would be able to make 2 comparison in parallel.

If you want to make only one comparison at a time, you can use _mm_cmpeq_sd to compare two 64 bits double or _mm_cmpeq_ss to compare two 32 bits float.

Note that _mm_cmpeq_sd and _mm_cmpeq_pd are SSE2 while _mm_cmpeq_ssand _mm_cmpeq_ps are SSE.

like image 76
zakinster Avatar answered Oct 02 '22 19:10

zakinster


In this context, "packed" means "several of the same type put into one lump" - so "packed single precision floating point" means 4 * 32 bit floating point numbers stored as a 128-bit value.

You either need to "pack" each value into the register using various PACK* instructions, or have the data already "packed" in memory, e.g. an array of (multiples of) 4 floating point values [that are suitably aligned].

Scalar means "one value" in the lower n bits of the register (e.g. a double would be the low 64 bits of a 128-bit SSE register).

like image 38
Mats Petersson Avatar answered Oct 02 '22 20:10

Mats Petersson