FIAS . Impressum . Privacy

Vectorizing functions having many return statement depending upon some conditions

Matthias Kretz [please enable javascript to see the address]
Tue Sep 24 18:56:02 CEST 2013


Hi Raman,

On Tuesday 24 September 2013 14:01:46 Raman Sehgal wrote:
> I am trying to vectorize some function that is having nested if else and
> many return statement depending upon various conditions.
> In my case i want to finally return a Vc vector.
> 
> I would appreciate if you give some sample code for that.

minimal example that should give you the idea:

float f(float x) {
  if (x > 1.f) {
    return x + 1.f;
  } else {
    return x - 1.f;
  }
}

float_v f(float_v x) {
  float_v r = x - 1.f;
  r(x > 1.f) = x + 1.f;
  return r;
}

The important thing you need to understand is conditional assignment.
I.e. when vectorizing you typically execute all branches and then blend the 
results. The important operator is (). Read "r(x < 1.f) = something" as "where 
x is less than 1 assign something to r".

BTW, in Vc master I'm experimenting with another expression that reads like 
this:
where(x < 1.f) | r = x + 1.f;

Cheers,
	Matthias

-- 
Dipl.-Phys. Matthias Kretz

Web:   http://compeng.uni-frankfurt.de/?mkretz

SIMD easy and portable: http://compeng.uni-frankfurt.de/?vc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://compeng.uni-frankfurt.de/pipermail/vc/attachments/20130924/7fcdca8d/attachment.pgp>


More information about the Vc mailing list
FIAS . Impressum . Privacy