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!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Performance of records with variant parts Date: Tue, 23 Mar 2021 10:31:01 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <07a56dcc-9e17-49b2-a980-3a5a2d265cedn@googlegroups.com> <23dcce3e-0db1-4417-a5d1-a05f03f74464n@googlegroups.com> <302c2e86-2379-46e0-b1f7-d69e7e14f9cfn@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 23 Mar 2021 09:31:03 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="125bd99a8fd2429a6cce27f79cf0d07d"; logging-data="4711"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bZQ552H/hoQ6OuYAj96pgJZ11N4qd7sc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 Cancel-Lock: sha1:dNN3q2ow4IEhrwEypfnjmfuVw8w= In-Reply-To: <302c2e86-2379-46e0-b1f7-d69e7e14f9cfn@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:61650 List-Id: On 3/22/21 11:11 PM, John Perry wrote: > > Current optimization is -O3 -funroll-loops -gnatn, but the behavior remains consistent. > > | 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; Interesting. With that optimization I would not expect this to differ noticeably from a record without discriminants. I note that all your nested declarations could be declared constant. Use of Long_Float is completely non-portable. If you want to look into this further, IIRC, there is an option that will output a low-level, Ada-like description of the IR that the front end produces. You'll have to look in the top-secret GNAT documentation to find it. -- Jeff Carter "[I]f you ask, 'Why does Ada do/have this?', the answer often makes you a better programmer." Chad R. Meiners 177