Thursday, 18 May 2017
BE VS LE data layout (&sldwi)
Say you have a vector int a = {1,2,3,4}, vector int b = {5,6,7,8}
The lay out of a in the memory on a BE machine is pretty simply, just as it is:
Because BE means high word is save in low address ( but it is natural for array access)
Addr0x 0 1 2 3
BE: [1,2,3,4]
On LE it is the opposite (high word is save in high address):
Addr0x 0 1 2 3
LE: [4,3,2,1]
say you have xxsldwi(a,b,3)
On BE: it is just 0 1 2 3 4 5 6 7
[1,2,3,4] [5,6,7,8]
The Result RT = {4,5,6,7}
if you want to use vec_shuffle to implement xxsldwi, you have to pass in
shuffle_vector((vector int)a, (vector int)b, 3,4,5,6), you can simply image BE
is acess from Left to right.
if you do for (int i = 0; i < 4; i++)
{
printf("RT[%d]=%d\n\n",i, RT[i]);
}
it is just :
c[0]=4
c[1]=5
c[2]=6
c[3]=7
But On LE, for the same array a and b,
it is just: 3 2 1 0 7 6 5 4
[4,3,2,1] [8,7,6,5]
The Result RT = [1,8,7,6] in the register
So no matter what, when xxsldwi(a,b,3), the word[3] of A, followed by
word[0], word[1] and word[2] will be put into the result vector register
if you want to use vec_shuffle to implement xxsldwi, you have to pass in
shuffle_vector((vector int)a, (vector int)b,5,6,7,0), you can simply image LE
is acess from right to left.
if you do for (int i = 0; i < 4; i++)
{
printf("RT[%d]=%d\n\n",i, RT[i]);
}
it is just :
c[0]=6
c[1]=7
c[2]=8
c[3]=1
No comments:
Post a Comment