Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!dcl-cs!aber-cs!athene!pcg From: pcg@cs.aber.ac.uk (Piercarlo Grandi) Newsgroups: comp.arch Subject: Re: loop unrolling (was:Re: Register Count) Message-ID: Date: 19 Jan 91 21:19:42 GMT References: <11566@pt.cs.cmu.edu> <5869@labtam.labtam.oz> Sender: cho@aber-cs.UUCP Organization: Coleg Prifysgol Cymru Lines: 44 Nntp-Posting-Host: teacho In-reply-to: pcg@cs.aber.ac.uk's message of 19 Jan 91 12:08:51 GMT On 19 Jan 91 12:08:51 GMT, pcg@cs.aber.ac.uk (Piercarlo Grandi) said: pcg> for (i = 0; i < K; i++) [ ... ] pcg> /* body 1 */; pcg> These can be rewritten as (4-way-unrolling): pcg> for (i = 0; (i+4) < K; i += 4) [ ... ] pcg> { pcg> /* body 1 */; pcg> /* body 1 */; pcg> /* body 1 */; pcg> /* body 1 */; pcg> } pcg> if (i < K) switch (K-i) pcg> { pcg> case 3: /* body 1 */; pcg> case 2: /* body 1 */; pcg> case 1: /* body 1 */; pcg> } OOPS: sorry, I forgot that 'i' might be used in 'body 1' or after the loop end; the corrected (hope no more errors!) version is: for (i = 0; (i+4) < K; i++) { /* body 1 */; i++; /* body 1 */; i++; /* body 1 */; i++; /* body 1 */; } if (i < K) switch (K-i) { case 3: /* body 1 */; i++; case 2: /* body 1 */; i++; case 1: /* body 1 */; i++; } This does not really change the argument in which this example was used, though. -- Piercarlo Grandi | ARPA: pcg%uk.ac.aber.cs@nsfnet-relay.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcsun!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk