Path: utzoo!attcan!uunet!mcsun!unido!rwthinf!truth!krischan From: krischan@truth.informatik.rwth-aachen.de (Christian Engel) Newsgroups: comp.os.os9 Subject: Passing parameters by registers is bad use?!?!? Summary: passing by stack is faster!!!! Keywords: C compiler, parameter passing Message-ID: <3537@rwthinf.UUCP> Date: 21 Sep 90 17:02:22 GMT Sender: news@rwthinf.UUCP Reply-To: krischan@truth.UUCP (Christian Engel) Followup-To: none Organization: Informatik RWTH Aachen Lines: 55 Hei, Kim Kempf and all netlanders! It's a time of more than one year that I'm wondering why the Microware C compiler passes the first two arguments of a function call by the registers D0 and D1 (usually). I've discussed this question with several friends experienced in compiler construction, but the more we are thinking about advantages of this strategy the less we see them. Let me explain the two most important arguments why we can't see the advantage: * The registers D0 and D1 are used as temporaries. Consequently the parameters passed by those registers has to be moved to another but save place by the called function. * On the other hand, unless a parameter isn't declared of class register the parameters can't be held in registers (D0, D1 or any other) since the called function could take their address by the unary & operator. If and only if the parameter isn't of class register and the compiler detects that there isn't any use of the address operator with the parameter inside the functions block the compiler is allowed to decide by its own to keep a variable in register. But I think those advanced features like automatically taking a variable to be of class register aren't implementedd in the Microware C compiler. This results in the conclusion that first of all a function has to move it's parameters passed by D0/D1 to a location on the stack. And that's what the Microware C compiler does -- tell me if I'm wrong. And this means the run time system has to execute *two* move operations with any parameter passed by registers: first the caller pushes them into the registers and second the called function moves them to it's local stack area. Other parameters not passed by D0/D1 are pushed to the stack by the caller directly. Main conclusion: passing parameters by register is slower than passing by stack. Exception: a copiler with sophisticated optimizations is able to recognize a parameter that can be passed by register. That means the parameter is pushed to a register that is free, that won't be used as temporary, and which address won't be taken by the & address operator inside the function body. An more about that: Any caller has to push the parameters in the correct registers. For this at the point where the code for the call is generated the compiler must know about the code of the called function. Alright, netlanders, tell me if I'm wrong. But if not I would suggest you, Kim Kempf and other compiler builders, forget passing parameters by registers!!! Krischan. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- krischan@informatik.rwth-aachen.de *** mcvax!unido!rwthinf!strange!krischan Christian Engel, Lehrstuhl fuer Informatik I, RWTH Aachen Ahornstr. 55, D-5100 Aachen, W. Germany