Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!ll-xn!mit-eddie!killer!pollux!dalsqnt!rpp386!jfh From: jfh@rpp386.UUCP (John F. Haugh II) Newsgroups: comp.lang.c Subject: Re: Shifting question Message-ID: <4246@rpp386.UUCP> Date: 22 Jul 88 00:49:49 GMT References: <705@bnr-rsc.UUCP> <11556@steinmetz.ge.com> <60290@sun.uucp> <1818@spar.SPAR.SLB.COM> <60670@sun.uucp> Reply-To: jfh@rpp386.UUCP (The Beach Bum) Organization: Big "D" Home for Wayward Hackers Lines: 35 In article <60670@sun.uucp> alanf%smile@Sun.COM (Alan Fargusson) writes: >In article <1818@spar.SPAR.SLB.COM>, hunt@spar.SPAR.SLB.COM (Neil Hunt) writes: >> We are talking factors of two in execution time for these functions. >> What a pain !! > >What is your solution? the solution which neil missed was to sacrifice code size. he wrote >> rshift = count > 0 ? count : 0; >> lshift = count < 0 ? -count : 0; >> >> for(j = 0; j < image->rows; j++) >> for(i = 0; i < image->cols; i++) >> image->pixels[i][j] = where the test could have been if (count < 0) { count = - count; for ... image->pixels[i][j] = (image->pixels[i][j] >> count); } else { for ... image->pixels[i][j] = (image->pixels[i][j] << count); } this does not suffer a significant decrease in performance, the only added overhead being the initial test and the possible negation. - john. -- John F. Haugh II +--------- Cute Chocolate Quote --------- HASA, "S" Division | "USENET should not be confused with UUCP: killer!rpp386!jfh | something that matters, like CHOCOLATE" DOMAIN: jfh@rpp386.uucp | -- with my apologizes