Topic
• 3 replies
• Latest Post - ‏2010-10-26T01:46:28Z by SystemAdmin
power-rox
2 Posts

Pinned topic Populating an altivec vector

‏2010-08-03T16:00:23Z |
Hello all,

I am trying to load a vector with some initial values. In simpler terms, how do I modify the following loop to use vectors?

int a200, b200;

for (i=0; i<200; i++)
{
a[i] = i;
b[i] = i;
}

now using vectors:

vector int a200, b200;
for (i=0;i<200;i++)
{
XXXXXXXXX
YYYYYYYYYY
}

What should X and Y statements be?

Thank you
Updated on 2010-10-26T01:46:28Z at 2010-10-26T01:46:28Z by SystemAdmin
• Katrin.Rollins
1 Post

Re: Populating an altivec vector

‏2010-10-25T01:45:48Z
power-rox wrote:
Hello all,

I am trying to load a vector with some initial values. In simpler terms, how do I modify the following loop to use vectors?

int a200, b200;

for (i=0; i<200; i++)
{
a[i] = i;
b[i] = i;
}

now using vectors:

vector int a200, b200;
for (i=0;i<200;i++)
{
XXXXXXXXX
YYYYYYYYYY
}

What should X and Y statements be?

Thank you

Anybody can answer it? Thank you! I've got the same problem, Can you share it with us?
• power-rox
2 Posts

Re: Populating an altivec vector

‏2010-10-25T16:58:09Z
power-rox wrote:
Hello all,

I am trying to load a vector with some initial values. In simpler terms, how do I modify the following loop to use vectors?

int a200, b200;

for (i=0; i<200; i++)
{
a[i] = i;
b[i] = i;
}

now using vectors:

vector int a200, b200;
for (i=0;i<200;i++)
{
XXXXXXXXX
YYYYYYYYYY
}

What should X and Y statements be?

Thank you

Anybody can answer it? Thank you! I've got the same problem, Can you share it with us?
This works

for (i=0;i<N;i+=4){
av[j] = vec_lde(0,&a[i]);
bv[j] = vec_lde(0,&b[i]);
j++;
}

t1=mysecond();
for (i=0;i<n/4; i++)
{
}
t2 = mysecond();
It would be nice if someone actually answered on this forum, but no one seems to be.
277 Posts

Re: Populating an altivec vector

‏2010-10-26T01:46:28Z
It may depend on which compiler you are using. According to the Freescale Altivec API vector literals are written as a parenthesized vector type followed by a parenthesized sequence of expressions. This syntax is supported by Apple's toolchain. GCC also supports vector constants written in curly braces like array initializers.

For example,
code
for (int i = 0; i < 200; i++) {
a[i] = (vector int)(i,i,i,i);
}
[/code]

Alternate syntax:
code
for (int i = 0; i < 200; i++) {
a[i] = (vector int){i,i,i,i};
}
[/code]
The relevant documentation:

http://www.freescale.com/webapp/sps/site/overview.jsp?code=DRPPCALTVC
http://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc/PowerPC-AltiVec-Built_002din-Functions.html#PowerPC-AltiVec-Built_002din-Functions
http://developer.apple.com/hardwaredrivers/ve/tutorial.html