Simple strength reduction on DUFFS_LOOP

A very easy optimization is just to do a strength reduction on the
operations preceeding the loop.

Instead of the following two lines…

int n = (width+7)/8;
switch (width % 8) {

…you can just use…

int n = (width+7)>>3;
switch (width & 0x03) {

I just don’t like the way the loop is nested. (Looks horrible.)
Something like…

switch (blah) {
	do {
		case 0:
		case 7:
		...
	} while (blah)
}

Seems to make a bit more sense. (However that might lead to one more jump
instruction, I’m not sure.) (It’s an asthetic thing, I know.)

Paul Braman
@Paul_Braman

A very easy optimization is just to do a strength reduction on the
operations preceeding the loop.

Instead of the following two lines…

int n = (width+7)/8;
switch (width % 8) {

…you can just use…

int n = (width+7)>>3;
switch (width & 0x03) {

Wouldn’t you expect the compiler to do this kind of strength reduction as
part of
its optimization anyway?

I just don’t like the way the loop is nested. (Looks horrible.)
Something like…

switch (blah) {
do {
case 0:
case 7:

} while (blah)
}

Seems to make a bit more sense. (However that might lead to one more jump
instruction, I’m not sure.) (It’s an asthetic thing, I know.)

Paul Braman
aeon at tampabay.rr.com

----- Original Message -----
From: aeon@tampabay.rr.com (Paul Braman)
To:
Sent: Monday, December 27, 1999 10:22 AM
Subject: [SDL] simple strength reduction on DUFFS_LOOP

Wouldn’t you expect the compiler to do this kind of strength reduction
as part of its optimization anyway?

Yeah, you probably would expect this to go on. That’s the only place I
can see where the loop can be generally optmized. You neither gain nor
lose anything for smart compilers by making the change, however.

Paul Braman
@Paul_BramanOn Mon, 27 Dec 1999, Prasanth Kumar wrote: