Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site kovacs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!bellcore!decvax!tektronix!hplabs!sdcrdcf!randvax!kovacs!day From: day@kovacs.UUCP (Dave Yost) Newsgroups: net.unix-wizards Subject: How to shave yet another cycle off getc/putc macros Message-ID: <236@kovacs.UUCP> Date: Wed, 5-Jun-85 02:29:03 EDT Article-I.D.: kovacs.236 Posted: Wed Jun 5 02:29:03 1985 Date-Received: Tue, 11-Jun-85 02:58:12 EDT Organization: Robt Abel & Assoc, Hollywood Lines: 43 Imagine, after all these years, finding a way to shave one more cycle off the getc and putc macros! On some well-known compilers, maybe all of them, the following getc() and putc() #defines will generate functionally equivalent but slightly more efficient code. How this works is left as an exercise for the reader. (On the VAX, you also get a free extra added bonus savings because of the Increased Instruction Set Computer [IISC] architecture.) NOTE: These are modified from 4.2bsd stdio.h. Other versions may differ. # ifdef slower #define getc(p) (--(p)->_cnt>=0? *(p)->_ptr++&0377:_filbuf(p)) #define putc(x,p) (--(p)->_cnt>=0? ((int)(*(p)->_ptr++=(unsigned)(x))):_flsbuf((unsigned)(x),p)) # else slower #define getc(p) (--(p)->_cnt < 0 ? _filbuf(p) : *(p)->_ptr++&0377) #define putc(x,p) (--(p)->_cnt < 0 ? \ _flsbuf((unsigned)(x),p) : ((int)(*(p)->_ptr++=(unsigned)(x)))) # endif slower - - - - - - - I also noticed that all the compilers I looked at (4) generate some almost-always-superfluous code to implement the almost-never-used (int) cast in the putc macro. they should be smart enough to refrain from generating it or they should optimize it out. On the vax: cvtbl (r0),r0 or on the 68000 movb a0@,d0 extw d0 extl d0 Or else maybe we should take that cast out of the putc macro. --dave