Path: utzoo!news-server.csri.toronto.edu!torsqnt!hybrid!scifi!bywater!uunet!lpi.liant.com!rcg From: rcg@lpi.liant.com (Rick Gorton) Newsgroups: comp.arch Subject: Re: Unusual instructions and constructions Summary: Flame coming Message-ID: <1991Mar15.163814.10033@lpi.liant.com> Date: 15 Mar 91 16:38:14 GMT References: <7571@mentor.cc.purdue.edu> <1991Mar14.013109.16636@kithrup.COM> <7850@mentor.cc.purdue.edu> Organization: Language Processors Inc., Framingham MA Lines: 78 The example was: foop (int x, int y) { struct div_and_rem t; t = divide(x,y); printf ("%d %d\n", t.quotient, t.remainder); } The 80X86 assembly code (from gcc 1.3) was: > foop: > pushl %ebp PPPP > movl %esp,%ebp PPPP > pushl %ebx PPPP > movl 8(%ebp),%eax > cltd > idivl 12(%ebp) > movl %eax,%ecx XXXX > movl %edx,%ebx XXXX > pushl %ebx XXXX > pushl %ecx XXXX > pushl $.LC0 XXXX > call printf XXXX > leal -4(%ebp),%esp EEEE > popl %ebx EEEE > leave EEEE > ret EEEE > In article <7850@mentor.cc.purdue.edu> hrubin@pop.stat.purdue.edu (Herman Rubin) writes: >This example has far too many loads and stores. Possibly this MIGHT not be >too important for a division, but how about something like frexp? The >operations may be register-register, in which case all these loads and >stores are inappropriate. Also, something this simple should be inlined; >if a subroutine call, there is the additional save/restore overhead which >has to be done somewhere. Sir: you have TOTALLY missed the boat here. The example was written as a subroutine/function. It was NOT written as a piece of inline code. See the lines marked "XXXX"? Those are for the user specified, machine translatable, machine primitive called "printf". It is a subroutine call to print the quotient and remainders. The lines marked "PPPP" are the subroutine PROLOGUE instructions, which are required because of the nature of the 80X86 architecture and calling conventions, and because this routine is NOT a leaf routine (it calls another routine). The instructions marked "EEEE" are the subroutine EPILOGUE instructions. So after getting to the heart of the matter, it takes 3 instructions to perform the "divide" idiom when the two inputs are ON THE STACK: > movl 8(%ebp),%eax > cltd > idivl 12(%ebp) You have been exceptionally vocal about the poor code quality of compilers, and yet you come up with a complaint like this? Your commentary leads me to believe that you are annoyed that your code executes slowly, but that you haven't made the slightest effort to understand the reasons why. Kind of like someone putting water in the gas tank of their car, and then telling the manufacturer of the engine that they need to improve the efficiency of the engine, because it works so poorly. And yet you want me, the compiler writer to try to fix your problem? Think again. What programming language do you use? What kind of hardware do you execute your programs on? Do you actually WRITE code at all? Or do you just complain about how slowly it executes? >Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399 >Phone: (317)494-6054 >hrubin@l.cc.purdue.edu (Internet, bitnet) {purdue,pur-ee}!l.cc!hrubin(UUCP) -- Richard Gorton rcg@lpi.liant.com (508) 626-0006 Language Processors, Inc. Framingham, MA 01760 Hey! This is MY opinion. Opinions have little to do with corporate policy.