Why do I keep devoting thought to this?

If you desperately needed to optimize every last cycle out of the loop, and you 
wanted to do this in a supported way, the trick would be two loops. Something 
like

for i = 1 to whatever;
  if a(i) >= 0 then do
    sum = sum + a(i);
    switch = 1;
    break? /* what is the PL/I to exit from a loop? */ ;
  end;
end;

for i = i to whatever;
  if a(i) > 0 then sum = sum + a(i);
end;

I'm not a PL/I coder so not sure if you need a test for i already == whatever 
when it gets to the second loop or whether it has already been incremented, 
etc. 

Probably faster than the original because avoids most of the a(i) == 0 cases.

Charles


-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of Robert Prins
Sent: Friday, August 4, 2017 10:48 AM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: Someone just too smart for his or her own good?

On 2017-08-04 13:41, Charles Mills wrote:
> OK, I get it. (Way too much time spent on this now.) The sum is also 
> to be printed if there are any zero values in a[whatever].
> 
> Is this a real business problem or an exercise in whatever?

The original code actually fills a set of buckets with values (or nothing), I 
just simplified the code to a loop over an array, changing the values in the 
array to do some testing, after first figuring out what was going on.

> I don't know the PL/I compiler but on a modern processor Store on 
> Condition potentially makes
> 
> if a(i) >= 0 then switch = 1;

It's more than likely that Enterprise PL/I V5.2 can already generate code that 
utilizes new features of the z14 systems.

Robert
--
Robert AH Prins
robert.ah.prins(a)gmail.com

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send email to 
lists...@listserv.ua.edu with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to