From: Paul Shirley Newsgroups: comp.os.msdos.djgpp Subject: Re: %d Date: Mon, 22 Sep 1997 15:25:40 +0100 Organization: wot? me? Lines: 33 Distribution: world Message-ID: References: <199709220850 DOT SAA00347 AT rabble DOT uow DOT edu DOT au> Reply-To: Paul Shirley NNTP-Posting-Host: chocolat.foobar.co.uk Mime-Version: 1.0 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article , Eli Zaretskii writes >> I heard a rumour somewhere (some internet page) that in a 32-bit compiler, >> you should always use 32-bit ints instead of shorts because they don't have >> to be "played with" so much in the registers (sorry, I didn't know how to >> say that). Is this true and would it really give that much of a speed gain? > >It is true that for some architectures, ints are faster than shorts. >However, when portability is an issue, IMHO, use shorts and don't look >back. In most programs you won't see the difference, since the optimizer >usually does a good job. The only place where you should use ints is >in tight loops, where the speed really matters; but an index in a loop >can always be declared int (if 16 bits are enough) without hampering >portability. This is not very good advice for a number of reasons. Theres the obvious one that some processors do handle them slower. Less obvious is that some processors (x86) actually generate longer opcodes and others (MIPS) generate extra code to sign extend shorts. The net result is for a 2 byte data saving you pay much more in extra code and potentially reduced cache effectiveness. gcc will optimise away most of this, even so we are seeing measurable speedups from switching shorts->ints in R3000 code. The only reasons to use shorts are: saving memory in arrays,interfacing to hardware. The portability argument is nonsense apart from the rare case where extra precision breaks code: I would call that code broken in the first place ;) --- Paul Shirley: my email address is 'obvious'ly anti-spammed