From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: renames usage Date: Tue, 5 Jan 2021 20:49:34 -0600 Organization: JSA Research & Innovation Message-ID: References: <5fedba8b$0$6186$426a74cc@news.free.fr> <5fedf478$0$21621$426a74cc@news.free.fr> <5fef180c$0$19476$426a74cc@news.free.fr> Injection-Date: Wed, 6 Jan 2021 02:49:35 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="19347"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:61048 List-Id: "Jeffrey R. Carter" wrote in message news:rss4sk$oqt$1@dont-email.me... > On 1/3/21 4:19 AM, Randy Brukardt wrote: >> >> In this case (a scalar return), the "copy" is a register, and it would be >> hard (and pointless) to eliminate that. > > Thanks for the clarification. I'm not sure I understand what you mean by > "the 'copy' is a register". Do you mean > > 1. The return value has to be copied into a register > > or > > 2. The return value is in a register and has to be copied elsewhere > > ? The latter: on every machine on which I'm familar, scalar function results are returned in a register. That serves as the "return object", and there's not really any way to eliminate that short of inlining the entire call. To "rename" the result, one has to copy the register somewhere (unless of course the renaming lives a short time with no subprogram calls), and that is effectively the same as the constant object declaration. OTOH, a composite object is typically returned with a reference in a register to memory allocated somewhere else (it might be passed in, it might be on a "secondary stack", it might be allocated, etc.), and one can rename rather than copy that memory. Of course, if the type requires "build-in-place", then a renames and an object are essentially the same again, as no temporary is allowed and the memory has to be passed into the function; either for the constant or for the renamed temporary. Which mainly goes to show that nothing is simple... :-) Randy.