Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.bugs.4bsd Subject: (more) missed optimizations in pcc Message-ID: <1214@umcp-cs.UUCP> Date: Sun, 18-Nov-84 07:34:03 EST Article-I.D.: umcp-cs.1214 Posted: Sun Nov 18 07:34:03 1984 Date-Received: Tue, 20-Nov-84 06:44:36 EST Distribution: net Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 55 Index: lib/pcc/local.c 4.2 Fix Description: The machine dependent expression optimizer doesn't handle "%" or "%=" by the constants which are powers of two. These can be done more simply as "&" or "&=". Repeat-By: Feed the following through /lib/ccom; look at the assembly: f () { register i,j; i = j % 3; /* ok */ i = j % 4; /* kinda the long way */ j %= 3; /* as above */ j %= 4; i = j % 1; /* check that previous fix still works */ j %= 1; } Fix: The following changes to local.c make it notice powers of two that are greater than 1 and turn the % or %= to an & or &=. RCS file: RCS/local.c,v retrieving revision 1.1 diff -c1 -r1.1 local.c *** /tmp/,RCSt1008635 Sun Nov 18 07:14:20 1984 --- local.c Sun Nov 18 07:13:55 1984 *************** *** 151,152 case FLD: --- 151,162 ----- + case MOD: + case ASG MOD: + /* convert %(const power of two) to &(mask) */ + /* mod by one is done elsewhere */ + if( nncon( p->in.right ) && ispow2( p->in.right->tn.lval )>0 ){ + p->in.op = p->in.op==MOD ? AND : ASG AND; + p->in.right->tn.lval--; + } + break; + case FLD: -- (This line accidently left nonblank.) In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690 UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland