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.
1 reply Latest Post - ‏2010-07-07T01:07:15Z by jadamcze
12 Posts

Pinned topic Sum of a "vector float"

‏2010-07-06T15:51:58Z |
Hello again,

I need to compute the 2-norm of a "vector float" rather often, and I was wondering what was the most efficient way of doing so. So far I've got

vector float x;
union { float f[4]; vector float v; } x2;

x2.v = x * x;
norm2 = x2.f[0] + x2.f[1] + x2.f[2] + x2.f[3];

I have serious doubts as to this being the optimal solution... I've seen the command vec_sum, but it is only described as handling integers. I've also seen this thread (, but it is three years and two major versions old.

Cheers, Pedro.
Updated on 2010-07-07T01:07:15Z at 2010-07-07T01:07:15Z by jadamcze
  • jadamcze
    219 Posts

    Re: Sum of a "vector float"

    ‏2010-07-07T01:07:15Z  in response to PedroGonnet
    I'm not aware of anything that would invalidate the discussion in the other thread.

    Unrolling a loop at least four times may be a simple way to improve performance, for example.

    If possible, a better solution may be to change your data layout. It's difficult to offer better suggestions without seeing more of the program context.