Question

Casting normal double* to a _m128d* is pretty easy and comprehensible. Suppose you have an array like this:

double arr[8] = {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0};

Then the _m128d presentation kinda would look like this:

_m128d m_arr[8] = { [1.0,2.0] , [3.0,4.0] , [5.0,6.0] , [7.0,8.0] };

because always 2 values are stored, if you can say that (that's how I imagine it). But how will the values be split up if I use a 3x3 matrix instead??? E.g.:

double mat[3][3] = { {1.0, 2.0, 3.0}, {1.0, 2.0, 3.0}, {1.0, 2.0, 3.0} };

I am trying to just sum up all values in a matrix but don't really get how to do this effictively with SSE, therefore I need to understand how the matrix is dealt with _m128d**. Does anybody know?

Était-ce utile?

La solution

The thing is that multidimensional arrays are stored in one continuous block of memory (the C standard guarantees this). So you can use a simple pointer to reference them:

double mat[3][3] = { {1.0, 2.0, 3.0}, {1.0, 2.0, 3.0}, {1.0, 2.0, 3.0} };
double *ptr = (double *)mat;

Then you can iterate over the 9 numbers using this pointer and dereference it to obtain a double, which then can be cast/converted to another type.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top