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 X-Received: by 2002:ae9:e118:: with SMTP id g24mr2411435qkm.212.1616451084522; Mon, 22 Mar 2021 15:11:24 -0700 (PDT) X-Received: by 2002:a25:1883:: with SMTP id 125mr936499yby.465.1616451084372; Mon, 22 Mar 2021 15:11:24 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 22 Mar 2021 15:11:24 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=2601:3c3:401:f550:f6d1:8c0b:6974:417; posting-account=JSxOkAoAAADa00TJoz2WZ_46XrZCdXeS NNTP-Posting-Host: 2601:3c3:401:f550:f6d1:8c0b:6974:417 References: <07a56dcc-9e17-49b2-a980-3a5a2d265cedn@googlegroups.com> <23dcce3e-0db1-4417-a5d1-a05f03f74464n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <302c2e86-2379-46e0-b1f7-d69e7e14f9cfn@googlegroups.com> Subject: Re: Performance of records with variant parts From: John Perry Injection-Date: Mon, 22 Mar 2021 22:11:24 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:61646 List-Id: On Monday, March 22, 2021 at 2:31:46 PM UTC-5, Jeffrey R. Carter wrote: > On 3/22/21 6:49 PM, John Perry wrote: > > Obj is an "in" parameter to a function. Do you need more than that? > Yes. > > What compiler and optimization option are you using? I would expect any compiler > (except GNAT at -O0) to optimize away any discriminant checks on direct accesses > to variant components in the branches of the case statement. > > Is Obj passed to any subprograms from the branches of the case statement? Are > any variant components accessed outside of the case statement? The compiler on the computer I'm using at the moment is GNAT Community 2020 (20200429-93) on x86_64-redhat-linux. I've also tested on MacOS, but I think that one is Community 2019. Both exhibit identical behavior. Current optimization is -O3 -funroll-loops -gnatn, but the behavior remains consistent. The full subprogram as it currently stands is below. As indicated in the OP, the *only* differences between this code and the non-variant code occurs lie in the variance of Thing_Type and the field names. | function Object_Intersect( obj: in Thing_Type; ray: in Ray_Type ) | return Long_Float | is | begin | case obj.kind is | when Sphere => | declare | eo: Vector := obj.center - ray.start; | v: Long_Float := eo * ray.dir; | begin | if v > 0.0 then | declare | disc: Long_Float := obj.radius2 - ( eo * eo - v * v ); | begin | if disc > 0.0 then | return v - Sqrt(disc); | end if; | end; | end if; | end; | when Plane => | declare | denom: Long_Float := obj.norm * ray.dir; | begin | if denom <= 0.0 then | return ( obj.norm * ray.start + obj.offset ) / ( -denom ); | end if; | end; | when None => | return far_away; | end case; | return Far_Away; | end Object_Intersect; john perry