Discussion:
Someone just too smart for his or her own good?
(too old to reply)
Robert Prins
2017-08-03 19:09:59 UTC
Permalink
Raw Message
Just came across the following, and please don't come back with pedantic
remarks about undeclared variables, the code is just to show what's there:

dcl sum fixed (7) init (-0.1);

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

if substr(unspec(sum), 25, 8) ^= '0d'bx then
put data(sum);

In other words if all a(i) are negative, nothing is printed. A comment in
the code suggests that this is faster code, on modern OoO z/OS systems,
than the more logical:

dcl sum fixed (7) init (-1);

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

It probably is if the value of whatever is in the order of 42 gazillion,
but any other thoughts about this?

Robert
--
Robert AH Prins
***@gmail.com
Some programming @ <https://prino.neocities.org/zOS/zOS%20Tools.html>

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Paul Gilmartin
2017-08-03 20:33:54 UTC
Permalink
Raw Message
Post by Robert Prins
Just came across the following, and please don't come back with pedantic
dcl sum fixed (7) init (-0.1);
I don't know what language this is, and I'm probsbly not skilled in it.
Regardless, "fixed" and "-0.1" seem contradictory; meriting a syntax
error.
Post by Robert Prins
for i = 1 to whatever;
if a(i) >= 0 then
sum = sum + a(i);
if a(i) > 0 then
sum = sum + a(i);
as long as testing, why bother to add 0?
Post by Robert Prins
if substr(unspec(sum), 25, 8) ^= '0d'bx then
put data(sum);
What's this testing for; in what representation? Is a single non-numeric
comparison cheaper than a numeric comparison?
Post by Robert Prins
In other words if all a(i) are negative, nothing is printed. A comment in
the code suggests that this is faster code, on modern OoO z/OS systems,
dcl sum fixed (7) init (-1);
for i = 1 to whatever;
if a(i) >= 0 then
if sum ^= -1 then
sum = sum + a(i);
else
sum = a(i);
end;
Unless the preponderance of the items are non-positive, the test
probably costs more than it saves.

I like to structure my loops, so neither boundary, the first item nor tne last,
requires special treatment. This violates that.

And I studiously avoid the over-and-under read, such as:

read X # Get first item.
if not eof then do
process X
read X # Get next item.
if eof then break
done
Post by Robert Prins
end;
It probably is if the value of whatever is in the order of 42 gazillion,
but any other thoughts about this?
None suitable for publication, although events of the past week have eroded that standard.

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Steve Beaver
2017-08-03 20:37:08 UTC
Permalink
Raw Message
It as elements of PL/I because of the DCL statement

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-***@LISTSERV.UA.EDU] On Behalf Of Paul Gilmartin
Sent: Thursday, August 3, 2017 3:35 PM
To: IBM-***@LISTSERV.UA.EDU
Subject: Re: Someone just too smart for his or her own good?
Post by Robert Prins
Just came across the following, and please don't come back with
dcl sum fixed (7) init (-0.1);
I don't know what language this is, and I'm probsbly not skilled in it.
Regardless, "fixed" and "-0.1" seem contradictory; meriting a syntax error.
Post by Robert Prins
for i = 1 to whatever;
if a(i) >= 0 then
sum = sum + a(i);
if a(i) > 0 then
sum = sum + a(i);
as long as testing, why bother to add 0?
Post by Robert Prins
if substr(unspec(sum), 25, 8) ^= '0d'bx then
put data(sum);
What's this testing for; in what representation? Is a single non-numeric comparison cheaper than a numeric comparison?
Post by Robert Prins
In other words if all a(i) are negative, nothing is printed. A comment
in the code suggests that this is faster code, on modern OoO z/OS
dcl sum fixed (7) init (-1);
for i = 1 to whatever;
if a(i) >= 0 then
if sum ^= -1 then
sum = sum + a(i);
else
sum = a(i);
end;
Unless the preponderance of the items are non-positive, the test probably costs more than it saves.

I like to structure my loops, so neither boundary, the first item nor tne last, requires special treatment. This violates that.

And I studiously avoid the over-and-under read, such as:

read X # Get first item.
if not eof then do
process X
read X # Get next item.
if eof then break
done
Post by Robert Prins
end;
It probably is if the value of whatever is in the order of 42
gazillion, but any other thoughts about this?
None suitable for publication, although events of the past week have eroded that standard.

-- gil

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

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Charles Mills
2017-08-03 21:02:37 UTC
Permalink
Raw Message
I think it is a fool's game guessing which bit of "tricky" source code will compile into faster executing machine code. Modern machines are plenty fast, but programmers are not getting any faster. Write maintainable code. Eschew obfuscation.

Charles


-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-***@LISTSERV.UA.EDU] On Behalf Of Robert Prins
Sent: Thursday, August 3, 2017 9:11 PM
To: IBM-***@LISTSERV.UA.EDU
Subject: Someone just too smart for his or her own good?

Just came across the following, and please don't come back with pedantic remarks about undeclared variables, the code is just to show what's there:

dcl sum fixed (7) init (-0.1);

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

if substr(unspec(sum), 25, 8) ^= '0d'bx then
put data(sum);

In other words if all a(i) are negative, nothing is printed. A comment in the code suggests that this is faster code, on modern OoO z/OS systems, than the more logical:

dcl sum fixed (7) init (-1);

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

It probably is if the value of whatever is in the order of 42 gazillion, but any other thoughts about this?

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Charles Mills
2017-08-04 00:31:22 UTC
Permalink
Raw Message
Certainly if one is looking to save a cycle or two then

if a(i) >= 0 then
sum = sum + a(i);

should be

if a(i) > 0 then
sum = sum + a(i);

because adding a(i) to sum when a(i) == 0 is a waste of a cycle or two.

Charles


-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-***@LISTSERV.UA.EDU] On Behalf Of Robert Prins
Sent: Thursday, August 3, 2017 12:11 PM
To: IBM-***@LISTSERV.UA.EDU
Subject: Someone just too smart for his or her own good?

Just came across the following, and please don't come back with pedantic remarks about undeclared variables, the code is just to show what's there:

dcl sum fixed (7) init (-0.1);

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

if substr(unspec(sum), 25, 8) ^= '0d'bx then
put data(sum);

In other words if all a(i) are negative, nothing is printed. A comment in the code suggests that this is faster code, on modern OoO z/OS systems, than the more logical:

dcl sum fixed (7) init (-1);

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

It probably is if the value of whatever is in the order of 42 gazillion, but any other thoughts about this?

Robert
--
Robert AH Prins
***@gmail.com
Some programming @ <https://prino.neocities.org/zOS/zOS%20Tools.html>

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

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
CM Poncelet
2017-08-04 02:13:24 UTC
Permalink
Raw Message
It is the unnecessary nested'if' that would degrade performance:

for i = 1 to whatever;
if a(i) >= 0 then /* <-- if #1 */
if sum ^= -1 then /* <-- if #2 */
sum = sum + a(i);
else
sum = a(i);
end;
if substr(unspec(sum), 25, 8) ^= '0d'bx then
put data(sum);


It would be more efficient (less machine code) if coded as:

for i = 1 to whatever;
if a(i) > 0 then
sum = sum + a(i);
end;
if substr(unspec(sum), 25, 8) ^= '0d'bx then
put data(sum);

CP
Post by Robert Prins
for i = 1 to whatever;
if a(i) >= 0 then
if sum ^= -1 then
sum = sum + a(i);
else
sum = a(i);
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Robert Prins
2017-08-04 07:56:46 UTC
Permalink
Raw Message
Post by Charles Mills
Certainly if one is looking to save a cycle or two then
if a(i) >= 0 then
sum = sum + a(i);
should be
if a(i) > 0 then
sum = sum + a(i);
because adding a(i) to sum when a(i) == 0 is a waste of a cycle or two.
Yes, but in this case it *IS* significant, because the initialization of a PL/I
"FIXED (7)" with -1.0 < init-value < 0 will set it to MINUS zero (zero with a
D-sign) and by adding zero to this will normalize the value to have a C-sign.

As I already write in the title, the gal or guy who wrote this code is just a
trifle too smart for her or his own good, I've been using PL/I for nearly 32
years, and until I used UNSPEC() on "sum", the code didn't make any sense to me.

FWIW, my original post contained a type,

if substr(unspec(sum), 25, 8) ^= '0d'bx then

should have been

if substr(unspec(sum), 29, 4) ^= 'd'bx then

or, like in the original code,

if substr(unspec(sum), 8*stg(sum)-3, 4) ^= 'd'bx then

Mea culpa, too much Intel assembler where hex constants must start with a zero...

Robert
Post by Charles Mills
-----Original Message-----
Sent: Thursday, August 3, 2017 12:11 PM
Subject: Someone just too smart for his or her own good?
dcl sum fixed (7) init (-0.1);
for i = 1 to whatever;
if a(i) >= 0 then
sum = sum + a(i);
end;
if substr(unspec(sum), 25, 8) ^= '0d'bx then
put data(sum);
dcl sum fixed (7) init (-1);
for i = 1 to whatever;
if a(i) >= 0 then
if sum ^= -1 then
sum = sum + a(i);
else
sum = a(i);
end;
It probably is if the value of whatever is in the order of 42 gazillion, but any other thoughts about this?
Robert
--
Robert AH Prins
----------------------------------------------------------------------
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
Robert AH Prins
robert(a)prino(d)org

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Robert Prins
2017-08-04 09:27:48 UTC
Permalink
Raw Message
Post by Robert Prins
Post by Charles Mills
Certainly if one is looking to save a cycle or two then
if a(i) >= 0 then
sum = sum + a(i);
should be
if a(i) > 0 then
sum = sum + a(i);
because adding a(i) to sum when a(i) == 0 is a waste of a cycle or two.
Yes, but in this case it *IS* significant, because the initialization of a PL/I
"FIXED (7)" with -1.0 < init-value < 0 will set it to MINUS zero (zero with a
D-sign) and by adding zero to this will normalize the value to have a C-sign.
As I already write in the title, the gal or guy who wrote this code is just a
trifle too smart for her or his own good, I've been using PL/I for nearly 32
years, and until I used UNSPEC() on "sum", the code didn't make any sense to me.
FWIW, my original post contained a type,
if substr(unspec(sum), 25, 8) ^= '0d'bx then
should have been
if substr(unspec(sum), 29, 4) ^= 'd'bx then
or, like in the original code,
if substr(unspec(sum), 8*stg(sum)-3, 4) ^= 'd'bx then
Mea culpa, too much Intel assembler where hex constants must start with a zero...
Following myself, I've submitted this RFE requesting an I- or W-type message to
flag this kind of (too) clever code, or a new RULES() option to outright ban it
with an E-type message:

http://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=108713

Robert
--
Robert AH Prins
robert.ah.prins(a)gmail.com
Some programming @ <https://prino.neocities.org/zOS/zOS%20Tools.html>

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Charles Mills
2017-08-04 13:22:42 UTC
Permalink
Raw Message
Oh geez, well then I rest my case that this code is too clever to be maintainable. The next programmer might not be any smarter than I.

(I'm not a PL/I expert -- I guess "fixed" means packed? I had guessed binary.)

If i is fairly large and there are a good number of a(i) == 0 then my point is still valid -- this has to be an expensive way of doing this.

What is the statement of the problem? What is the snippet supposed to accomplish? "For a table of packed values a[whatever], print the sum of all of the positive values, unless that sum is zero?" Do I have that right?

I would be stunned if the code below performs better than -- and not worse than, assuming a fair number of zero values -- the most obvious logic

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

Charles


-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-***@LISTSERV.UA.EDU] On Behalf Of Robert Prins
Sent: Friday, August 4, 2017 2:58 AM
To: IBM-***@LISTSERV.UA.EDU
Subject: Re: Someone just too smart for his or her own good?
Post by Charles Mills
Certainly if one is looking to save a cycle or two then
if a(i) >= 0 then
sum = sum + a(i);
should be
if a(i) > 0 then
sum = sum + a(i);
because adding a(i) to sum when a(i) == 0 is a waste of a cycle or two.
Yes, but in this case it *IS* significant, because the initialization of a PL/I "FIXED (7)" with -1.0 < init-value < 0 will set it to MINUS zero (zero with a
D-sign) and by adding zero to this will normalize the value to have a C-sign.

As I already write in the title, the gal or guy who wrote this code is just a trifle too smart for her or his own good, I've been using PL/I for nearly 32 years, and until I used UNSPEC() on "sum", the code didn't make any sense to me.

FWIW, my original post contained a type,

if substr(unspec(sum), 25, 8) ^= '0d'bx then

should have been

if substr(unspec(sum), 29, 4) ^= 'd'bx then

or, like in the original code,

if substr(unspec(sum), 8*stg(sum)-3, 4) ^= 'd'bx then

Mea culpa, too much Intel assembler where hex constants must start with a zero...

Robert
Post by Charles Mills
-----Original Message-----
On Behalf Of Robert Prins
Sent: Thursday, August 3, 2017 12:11 PM
Subject: Someone just too smart for his or her own good?
dcl sum fixed (7) init (-0.1);
for i = 1 to whatever;
if a(i) >= 0 then
sum = sum + a(i);
end;
if substr(unspec(sum), 25, 8) ^= '0d'bx then
put data(sum);
dcl sum fixed (7) init (-1);
for i = 1 to whatever;
if a(i) >= 0 then
if sum ^= -1 then
sum = sum + a(i);
else
sum = a(i);
end;
It probably is if the value of whatever is in the order of 42 gazillion, but any other thoughts about this?
Robert
--
Robert AH Prins
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send
--
Robert AH Prins
robert(a)prino(d)org

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

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Charles Mills
2017-08-04 13:41:05 UTC
Permalink
Raw Message
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?

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;

pretty fast.

Charles


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

Oh geez, well then I rest my case that this code is too clever to be maintainable. The next programmer might not be any smarter than I.

(I'm not a PL/I expert -- I guess "fixed" means packed? I had guessed binary.)

If i is fairly large and there are a good number of a(i) == 0 then my point is still valid -- this has to be an expensive way of doing this.

What is the statement of the problem? What is the snippet supposed to accomplish? "For a table of packed values a[whatever], print the sum of all of the positive values, unless that sum is zero?" Do I have that right?

I would be stunned if the code below performs better than -- and not worse than, assuming a fair number of zero values -- the most obvious logic

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

Charles

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Steve Smith
2017-08-04 14:02:47 UTC
Permalink
Raw Message
In PL/I "FIXED" means neither packed nor binary; it can be either. The
relevant attribute is "DEC" or "BIN" (short forms), and the default is
"DEC".

Using UNSPEC to test the sign is absolutely ridiculous. Sure, that's "too
clever", but it really shows that the writer was a wanker. Nevertheless,
you have no case for an RFE. Any feature can be abused or misused.

Anyway, it's been really difficult to make out what this post is about.
What's with all the discussion about what's in the loop, "negative zero",
etc. if the UNSPEC is the issue?

sas
Post by Steve Beaver
-----Original Message-----
Behalf Of Charles Mills
Sent: Friday, August 4, 2017 6:24 AM
Subject: Re: Someone just too smart for his or her own good?
Oh geez, well then I rest my case that this code is too clever to be
maintainable. The next programmer might not be any smarter than I.
(I'm not a PL/I expert -- I guess "fixed" means packed? I had guessed binary.)
If i is fairly large and there are a good number of a(i) == 0 then my
point is still valid -- this has to be an expensive way of doing this.
What is the statement of the problem? What is the snippet supposed to
accomplish? "For a table of packed values a[whatever], print the sum of all
of the positive values, unless that sum is zero?" Do I have that right?
I would be stunned if the code below performs better than -- and not worse
than, assuming a fair number of zero values -- the most obvious logic
for i = 1 to whatever;
if a(i) > 0 then sum = sum + a(i);
end;
if sum > 0 then put data(sum);
Charles
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
David Crayford
2017-08-04 14:43:27 UTC
Permalink
Raw Message
Post by Steve Smith
Using UNSPEC to test the sign is absolutely ridiculous. Sure, that's "too
clever", but it really shows that the writer was a wanker. Nevertheless,
you have no case for an RFE. Any feature can be abused or misused.
I'm not sure what wanker means where you live but it probably has a
different connotation where I do ;) Classic Friday quote.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Steve Smith
2017-08-04 17:33:52 UTC
Permalink
Raw Message
It's not really a word where I live (OH, USA), but in the words of my
favorite /. sig: "Every now and then I like to masterbate a new word into
my vocabulary, even if I don't know what it means". ;-)

sas

p.s. seems I don't even know how to spell that word. Yay for me. :-)
Post by David Crayford
Post by Steve Smith
Using UNSPEC to test the sign is absolutely ridiculous. Sure, that's "too
clever", but it really shows that the writer was a wanker. Nevertheless,
you have no case for an RFE. Any feature can be abused or misused.
I'm not sure what wanker means where you live but it probably has a
different connotation where I do ;) Classic Friday quote.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
sas

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Bernd Oppolzer
2017-08-04 15:05:51 UTC
Permalink
Raw Message
Post by Steve Smith
In PL/I "FIXED" means neither packed nor binary; it can be either. The
relevant attribute is "DEC" or "BIN" (short forms), and the default is
"DEC".
Using UNSPEC to test the sign is absolutely ridiculous. Sure, that's "too
clever", but it really shows that the writer was a wanker. Nevertheless,
you have no case for an RFE. Any feature can be abused or misused.
IMO, the case for the RFE could be
that programs that rely on the initialization of

DCL SUM DEC FIXED (7) INIT (-0.1);

with negative zero (X'0000000d')
should be flagged; this is bad practice, and I would like
such initializations to be flagged as ERROR (not only warning)
and to be told by the error message, that the initialization will be
POSITIVE zero from now on. (Losing decimal digits to the right of
the decimal point should only be a warning, IMO).

BTW, it's not the UNSPEC per se and not the content of the loop,
which is subject of the discussion, IMO. The UNSPEC is needed
if you want to test for negative zero, after all (the UNSPEC is ok,
but the usage in this case is questionable).

See more discussions on this topic on the PL/1 mailing list
(PL1-***@LISTSERV.DARTMOUTH.EDU), if you are interested.

Kind regards

Bernd Oppolzer
Post by Steve Smith
Anyway, it's been really difficult to make out what this post is about.
What's with all the discussion about what's in the loop, "negative zero",
etc. if the UNSPEC is the issue?
sas
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Robert Prins
2017-08-04 15:45:36 UTC
Permalink
Raw Message
Post by Charles Mills
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.
Post by Charles Mills
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 ***@listserv.ua.edu with the message: INFO IBM-MAIN
Charles Mills
2017-08-04 17:44:47 UTC
Permalink
Raw Message
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-***@LISTSERV.UA.EDU] On Behalf Of Robert Prins
Sent: Friday, August 4, 2017 10:48 AM
To: IBM-***@LISTSERV.UA.EDU
Subject: Re: Someone just too smart for his or her own good?
Post by Charles Mills
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.
Post by Charles Mills
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 ***@listserv.ua.edu with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Steve Beaver
2017-08-04 18:00:20 UTC
Permalink
Raw Message
Charles. PL/1 and REXX are about the same The break would be a goto

Sent from my iPhone

Sorry for any grammar problems
Post by Charles Mills
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-----
Sent: Friday, August 4, 2017 10:48 AM
Subject: Re: Someone just too smart for his or her own good?
Post by Charles Mills
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.
Post by Charles Mills
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,
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Edward Finnell
2017-08-04 02:44:07 UTC
Permalink
Raw Message
It's been too long, would compiler OPT(2) make it better?


In a message dated 8/3/2017 9:14:44 P.M. Central Daylight Time,
***@BCS.ORG.UK writes:

It is the unnecessary nested'if' that would degrade performance

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
CM Poncelet
2017-08-04 05:27:04 UTC
Permalink
Raw Message
From memory, the PL/I compiler option 'LIST' should produce an assembler
listing and show 2 CLC's when using nested if's (else only 1 CLC). I
doubt that optimising the compiler could improve this, because the
generated machine code would(logically) stillhave to process the 2
nested if's.
Post by Edward Finnell
It's been too long, would compiler OPT(2) make it better?
In a message dated 8/3/2017 9:14:44 P.M. Central Daylight Time,
It is the unnecessary nested'if' that would degrade performance
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Kenneth J. Kripke
2017-08-04 06:10:23 UTC
Permalink
Raw Message
dcl sum fixed (7) init (-0.1); /* Packed Decimal? */
for i = 1 to whatever;
if a(i) >= 0 then
sum = sum + a(i);
if a(i) > 0 then
sum = sum + a(i);
as long as testing, why bother to add 0?
if substr(unspec(sum), 25, 8) ^= '0d'bx then /* test the sign of the
number? */
put data(sum);
Unspec function returns a binary representation



Sincerely;



Kenneth J. Kripke



***@gmail.com




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