Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!gatech!mcnc!rti!xyzzy!tiktok!meissner From: meissner@tiktok.dg.com (Michael Meissner) Newsgroups: comp.lang.c Subject: Re: optimization (was: Re: swap(x,y)) Message-ID: <1221@xyzzy.UUCP> Date: 18 Sep 89 17:19:28 GMT References: <4151@buengc.BU.EDU> <14357@bloom-beacon.MIT.EDU> Sender: usenet@xyzzy.UUCP Reply-To: meissner@tiktok.UUCP (Michael Meissner) Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 42 In article <14357@bloom-beacon.MIT.EDU> scs@adam.pika.mit.edu (Steve Summit) writes: | In article <4151@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: | >>And by the way: why do you need an operator for swapping? | >Because if a machine can do it with a coupla gates and half a cycle, | >I'd like to do it with an operator. | > | >Some machines (we've already seen an example involving a DG) have | >opcodes to swap two values, and it seems a bit ludicrous to code | >some elaborate swapping routine when the optimizer is just going | >to throw it all out and insert the single instruction. | > | >Still, any good optimizer will catch all the obvious cases, but it's | >gotta be harder to write a compiler to do it that way than to implement | >just another canned routine. | | I'd much, much rather that the optimizer bend 'way over backwards | to detect cases which reduce to simple opcodes, than have the | language cluttered up with features corresponding to every | "useful" operation any architecture has ever offered, with the | resulting requirement that every compiler writer implement | emulations for all those operations not directly supported by his | particular machine. (True, as Blair seems to suggest, the | emulations could be portable, "canned" routines.) | | Someone has already posted an example of a compiler/optimizer | which translated the dumb, obvious, temporary-variable-using | exchange into a single EXCH instruction. I cheered when I saw | that -- it's the right way to do optimizations. Even though the DG MV and Eclipse computers support a SWAP instruction, none of the compilers that I'm aware of use it (and I have worked on two different compilers for the DG systems). About the only time I can recall using it in assembly language was to work with instructions that expect things in different fixed registers. But then, when you only have 4 integer registers (and of those registers, only 2 can be used for word memory references), the number of times you need to swap registers is vanishingly small. -- Michael Meissner, Data General. Uucp: ...!mcnc!rti!xyzzy!meissner If compiles were much Internet: meissner@dg-rtp.DG.COM faster, when would we Old Internet: meissner%dg-rtp.DG.COM@relay.cs.net have time for netnews?