Article View: comp.arch
Article #111Re: A challenge to the anti-goto
From: Herman Rubin
Date: Sat, 31 Oct 1992 22:30
Date: Sat, 31 Oct 1992 22:30
82 lines
3249 bytes
3249 bytes
In article <Bwznzx.Dr1@mentor.cc.purdue.edu> hrubin@mentor.cc.purdue.edu (Herman Rubin) writes:
>In article <1css0nINNc51@agate.berkeley.edu> jhauser@pine.CS.Berkeley.EDU (John Hauser) writes:
To try to clarify the program, I am writing it with ONLY gotos for transfer of
control. This should enable those who have difficulty following the pattern to
see what it is doing.
extern B;
n = 0; m = 0; b = B;
goto start;
add: n += 1;
start: g = ...;
if(g==1)goto add;
if(g==2)goto label1;
if(g==3)goto start;
if(g==4)goto label2;
if(g==5||g==6)goto start;
if(g==7){g4=1; goto label3;};
if(g==8){h = ...; g4=h>>1;
if(h&1){g4+=2; goto label3}
goto label4;}
if(g > 8 && g <= 12) goto start;
g16 = (g-9)>>4;
g &= 3;
if(g==1)goto label5;
if(g==2 || g==3)goto start;
h = ...;
g4 = (h+1)>>1;
if(h&1){j=6; goto labelh;};
j = 7;
g = ...;
if(g%3 != 2)goto start;
loop: if(bit) goto labelh;
j += 1;
g = ...;
if((2<<(g-1)/j)&1 == 0)goto start;
goto loop;
labelh: i = C(j); b >>= 1;
if(i==j || i==0)goto labelh:
m |= b;
if(i==1)goto label1;
if(i==2)goto label2;
if(i==3)goto label3;
if(i==4)goto label4;
label5: b >>= g16; m |= b; g = ...;
if(bit){if(g&1)goto label2; goto label1;}
g4 = (g+1)>>1;
if(g&1)goto label3;
label4: g = ...;
if(g4 < g){m |= (b>>g4 | b>>g); goto label1;
m |= b>>g;
if(bit)goto label1;
b >>= 1;
label3: b >>= g4: m |= b; b <<= 1;
label2: g = ...; m |= (b>>g);
label1:
Now, depending on the machine, it may pay to use switch statements, and
I have not used them only to make sure that I do not get something wrong.
I have no objection to using high level constructs when they speed things
up. There are things which might or might not speed up the program which
would make some changes; one of my correspondents questioned the b<<=1
statement at the end of label3. Now this can be replaced by
if(bit)goto label1, which gives the same bit performance. There is
one other alternative of this type. Do not worry about the performance
of anything involved with labelh; it is important that it be correct,
but otherwise only that it not be extremely slow. I might very well
do it otherwise, but the code would be longer.
The challenge still stands; code this in a HLL without using gotos, and
try to get as fast code. Switch statements which could be inserted into
this program as well without changing what is done should be considered
neutral, as I am willing to do it.
but anything not really expensive can be tolerated.
--
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
Phone: (317)494-6054
hrubin@snap.stat.purdue.edu (Internet, bitnet)
{purdue,pur-ee}!snap.stat!hrubin(UUCP)
Technical Details
Message-ID:
<Bx0BuG.s4@mentor.cc.purdue.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!purdue!mentor.cc.purdue.edu!hrubinReferences:
<BwxsF6.3DF@mentor.cc.purdue.edu> <1css0nINNc51@agate.berkeley.edu> <Bwznzx.Dr1@mentor.cc.purdue.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.arch,comp.lang.misc Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!purdue!mentor.cc.purdue.edu!hrubin From: hrubin@mentor.cc.purdue.edu (Herman Rubin) Subject: Re: A challenge to the anti-goto Message-ID: <Bx0BuG.s4@mentor.cc.purdue.edu> Organization: Purdue University Statistics Department References: <BwxsF6.3DF@mentor.cc.purdue.edu> <1css0nINNc51@agate.berkeley.edu> <Bwznzx.Dr1@mentor.cc.purdue.edu> Date: Sat, 31 Oct 1992 22:30:15 GMT Lines: 82