optimization (was: Re: swap(x,y))

Michael Meissner meissner at tiktok.dg.com
Tue Sep 19 03:19:28 AEST 1989


In article <14357 at bloom-beacon.MIT.EDU> scs at adam.pika.mit.edu (Steve Summit) writes:
| In article <4151 at buengc.BU.EDU> bph at 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 at dg-rtp.DG.COM			faster, when would we
Old Internet:	meissner%dg-rtp.DG.COM at relay.cs.net	have time for netnews?



More information about the Comp.lang.c mailing list