Hi all,I don't know the language but it seems to me if after each "when"
I'm, sort-of, looking at optimising the flow of some code. It doesn't really >serve a lot of real-life purpose, but I'm just curious.
This is the original PL/I code, where I walk through a set of items in a linked
list, the outer do-loop, and a PL/I "SELECT" statement is comparable to a Pascal
(or C, where every selection is followed by a "break") case statement.
/*------------------------------------------------------------------+
| Process set of data |
+------------------------------------------------------------------*/
do list_ptr = list_own repeat list_nxt
while(list_ptr ^= sysnull());
select;
/*--------------------------------------------------------------+
| Process countries (7,353 vvvv *S* T383R13 2025-03-26T14:30) |
+--------------------------------------------------------------*/
when (data_list.split ^= '#' &
data_list.split ^= '!' &
data_list.cnty ^= '* ')
...
/*--------------------------------------------------------------+
| Process splits (4,923 vvvv *S* T383R13 2025-03-26T14:30) |
+--------------------------------------------------------------*/
when (data_list.split = '!')
...
/*--------------------------------------------------------------+
| Process days (446 vvvv *S* T383R13 2025-03-26T14:30) |
+--------------------------------------------------------------*/
when (data_list.split = '#')
...
other;--- Synchronet 3.21d-Linux NewsLink 1.2
end;
end;
During our basic PL/I training, almost 40 years ago, we were taught to put the
most frequently occurring case as the first, but given that a PL/I "SELECT" >statement can have two possible formats, i.e.
select(myvar);
when(value1)...
when(value2)...
other...
end;
and
select;
when(var = value)...
when(other_var = other_value)...
other...
end;
or, like in the real code above, multiple conditions, I wonder if the above is
really optimal, as e.g. moving the second "WHEN" into the first position would
allow removing the now redundant "data_list.split ^= '!'" from the now second >original first, eliminating a compare instruction, with a possible mispredicted
jump.
Any opinions?
Robert
On Thu, 3 Apr 2025 11:26:34 +0000, Robert Prins wrote:
Hi all,
I'm, sort-of, looking at optimising the flow of some code. It doesn't really
serve a lot of real-life purpose, but I'm just curious.
This is the original PL/I code, where I walk through a set of items in a linked
list, the outer do-loop, and a PL/I "SELECT" statement is comparable to a Pascal
(or C, where every selection is followed by a "break") case statement.
/*------------------------------------------------------------------+
| Process set of data |
+------------------------------------------------------------------*/
do list_ptr = list_own repeat list_nxt
while(list_ptr ^= sysnull());
select;
/*--------------------------------------------------------------+
| Process countries (7,353 vvvv *S* T383R13 2025-03-26T14:30) |
+--------------------------------------------------------------*/
when (data_list.split ^= '#' &
data_list.split ^= '!' &
data_list.cnty ^= '* ')
...
/*--------------------------------------------------------------+
| Process splits (4,923 vvvv *S* T383R13 2025-03-26T14:30) |
+--------------------------------------------------------------*/
when (data_list.split = '!')
...
/*--------------------------------------------------------------+
| Process days (446 vvvv *S* T383R13 2025-03-26T14:30) |
+--------------------------------------------------------------*/
when (data_list.split = '#')
...
I don't know the language but it seems to me if after each "when"
there is a return, it is possible doing something as
when (data_list.split = '!') doOperation return
when (data_list.split = '#') doOperation return
and the remain the code that follow
"when (data_list.split ^= '#' &data_list.split ^'!'&data_list.cnty ^= '* ')"
other;
end;
end;
During our basic PL/I training, almost 40 years ago, we were taught to put the
most frequently occurring case as the first, but given that a PL/I "SELECT" >> statement can have two possible formats, i.e.
select(myvar);
when(value1)...
when(value2)...
other...
end;
and
select;
when(var = value)...
when(other_var = other_value)...
other...
end;
or, like in the real code above, multiple conditions, I wonder if the above is
really optimal, as e.g. moving the second "WHEN" into the first position would
allow removing the now redundant "data_list.split ^= '!'" from the now second
original first, eliminating a compare instruction, with a possible mispredicted
jump.
Any opinions?
Robert
Rosario19 <Ros@invalid.invalid> wrote:That's what PL/I does anyway, unlike C and some other new-fangled languages, it
On Thu, 3 Apr 2025 11:26:34 +0000, Robert Prins wrote:
Hi all,
I'm, sort-of, looking at optimising the flow of some code. It doesn't really
serve a lot of real-life purpose, but I'm just curious.
This is the original PL/I code, where I walk through a set of items in a linked
list, the outer do-loop, and a PL/I "SELECT" statement is comparable to a Pascal
(or C, where every selection is followed by a "break") case statement.
/*------------------------------------------------------------------+
| Process set of data |
+------------------------------------------------------------------*/
do list_ptr = list_own repeat list_nxt
while(list_ptr ^= sysnull());
select;
/*--------------------------------------------------------------+
| Process countries (7,353 vvvv *S* T383R13 2025-03-26T14:30) |
+--------------------------------------------------------------*/
when (data_list.split ^= '#' &
data_list.split ^= '!' &
data_list.cnty ^= '* ')
...
/*--------------------------------------------------------------+
| Process splits (4,923 vvvv *S* T383R13 2025-03-26T14:30) |
+--------------------------------------------------------------*/
when (data_list.split = '!')
...
/*--------------------------------------------------------------+
| Process days (446 vvvv *S* T383R13 2025-03-26T14:30) |
+--------------------------------------------------------------*/
when (data_list.split = '#')
...
I don't know the language but it seems to me if after each "when"
there is a return, it is possible doing something as
when (data_list.split = '!') doOperation return
when (data_list.split = '#') doOperation return
and the remain the code that follow
"when (data_list.split ^= '#' &data_list.split ^'!'&data_list.cnty ^= '* ')"
other;
end;
end;
During our basic PL/I training, almost 40 years ago, we were taught to put the
most frequently occurring case as the first, but given that a PL/I "SELECT" >>> statement can have two possible formats, i.e.
select(myvar);
when(value1)...
when(value2)...
other...
end;
and
select;
when(var = value)...
when(other_var = other_value)...
other...
end;
or, like in the real code above, multiple conditions, I wonder if the above is
really optimal, as e.g. moving the second "WHEN" into the first position would
allow removing the now redundant "data_list.split ^= '!'" from the now second
original first, eliminating a compare instruction, with a possible mispredicted
jump.
IrCOd check for ! and # in either order, and move the stuff from the first test to the rCLotherwiserCY (if IrCOm reading this right, IrCOm not on my computer
to look at this).
The problem with trying to write rCLoptimalrCY code is that you never can be sure what the compiler is going to do with it, even from release to
release.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (1 / 5) |
| Uptime: | 01:04:05 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
10 files (20,373K bytes) |
| Messages: | 264,187 |