From: John Perry <john.perry@usm.edu>
Subject: Re: Performance of records with variant parts
Date: Mon, 22 Mar 2021 15:11:24 -0700 (PDT) [thread overview]
Message-ID: <302c2e86-2379-46e0-b1f7-d69e7e14f9cfn@googlegroups.com> (raw)
In-Reply-To: <s3arav$3mf$1@dont-email.me>
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
next prev parent reply other threads:[~2021-03-22 22:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 17:02 Performance of records with variant parts John Perry
2021-03-22 17:32 ` Jeffrey R. Carter
2021-03-22 17:49 ` John Perry
2021-03-22 17:54 ` John Perry
2021-03-22 19:31 ` Jeffrey R. Carter
2021-03-22 22:11 ` John Perry [this message]
2021-03-23 9:31 ` Jeffrey R. Carter
2021-03-23 14:27 ` Simon Wright
2021-03-23 23:00 ` John Perry
2021-03-23 23:27 ` Jeffrey R. Carter
2021-03-26 15:38 ` Stephen Leake
2021-03-26 15:44 ` John Perry
2021-03-30 7:12 ` Emmanuel Briot
2021-04-01 0:03 ` John Perry
2021-04-01 6:45 ` Emmanuel Briot
2021-04-01 13:38 ` Niklas Holsti
2021-04-02 16:07 ` John Perry
2021-03-22 17:39 ` Dmitry A. Kazakov
2021-03-22 17:45 ` John Perry
2021-03-22 18:07 ` Dmitry A. Kazakov
2021-03-22 18:23 ` John Perry
2021-03-22 20:30 ` Dmitry A. Kazakov
2021-03-22 18:59 ` Niklas Holsti
2021-03-22 21:54 ` John Perry
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox