Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ames!oliveb!sun!david From: david@sun.UUCP Newsgroups: comp.sys.m68k Subject: Re: Incidentally ... (dbra loops) Message-ID: <16360@sun.uucp> Date: Wed, 8-Apr-87 13:55:27 EST Article-I.D.: sun.16360 Posted: Wed Apr 8 13:55:27 1987 Date-Received: Sat, 11-Apr-87 07:41:54 EST References: <362@sbcs.UUCP> <1466@ncr-sd.SanDiego.NCR.COM> <580@plx.UUCP> <6139@mimsy.UUCP> <75@eps2.UUCP> Organization: Sun Microsystems, Mountain View Lines: 51 In article <75@eps2.UUCP> jon@eps2.UUCP (Jonathan Hue) writes: >On this Sun-3/160 running 3.2, the compiler won't generate the dbra. However, >the object code optimizer will. But the only way I know of to find this out >is to adb the executable or a .o (I know I am not as clever as you, am I >missing something? I didn't think you could get an optimized .s). cc -O -S foo.c In article <6139@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > In article <6134@mimsy.UUCP> I wrote: > >[use] while (--j >= 0) [rather than while (j--)] > > I poked around today and discovered that Sun's compiler, at least, > will turn > > register short j; /* but not `register int j' */ > while (--j != -1) > ... > > into a `dbra' loop. If you are willing to put machine dependent > source optimisations into your C code, this might be something to > consider (at least for inner loops). Be a good citizen and hide it with macros... #ifdef mc68000 typedef short LOOP_T; #define LOOP_DECR(var) (--(var) != -1) #else typedef int LOOP_T; #define LOOP_DECR(var) (--(var) >= 0) #endif register LOOP_T j; while (LOOP_DECR(j)) something; which leads us to the mystic loop macro ... #define LOOP(count, op) do { register LOOP_T _loop = (count); if (--_loop >= 0) do { op; } while (LOOP_DECR(_loop)); } while (0) (end of line backslashes omitted for clarity) -- David DiGiacomo, Sun Microsystems, Mt. View, CA sun!david david@sun.com Disclaimer: blah blah blah