Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
3 replies Latest Post - ‏2010-10-26T01:46:28Z by SystemAdmin
power-rox
power-rox
2 Posts
ACCEPTED ANSWER

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
    Katrin.Rollins
    1 Post
    ACCEPTED ANSWER

    Re: Populating an altivec vector

    ‏2010-10-25T01:45:48Z  in response to power-rox
    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
      power-rox
      2 Posts
      ACCEPTED ANSWER

      Re: Populating an altivec vector

      ‏2010-10-25T16:58:09Z  in response to Katrin.Rollins
      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++)
      {
      cv[i] = vec_add(av[i],bv[i]);
      }
      t2 = mysecond();
      It would be nice if someone actually answered on this forum, but no one seems to be.
  • SystemAdmin
    SystemAdmin
    277 Posts
    ACCEPTED ANSWER

    Re: Populating an altivec vector

    ‏2010-10-26T01:46:28Z  in response to power-rox
    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