From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a0c:983b:: with SMTP id c56mr2412531qvd.131.1562318690351; Fri, 05 Jul 2019 02:24:50 -0700 (PDT) X-Received: by 2002:a05:6830:1086:: with SMTP id y6mr2247102oto.22.1562318689940; Fri, 05 Jul 2019 02:24:49 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!m24no8700920qtm.0!news-out.google.com!g23ni232qtq.1!nntp.google.com!m24no8700906qtm.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 5 Jul 2019 02:24:49 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=185.34.132.4; posting-account=Srm5lQoAAAAEMX9rv2ilEKR6FDPapmSq NNTP-Posting-Host: 185.34.132.4 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Odd AVR-Ada code generation issue with constant record type From: Mark Lorenzen Injection-Date: Fri, 05 Jul 2019 09:24:50 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:56818 Date: 2019-07-05T02:24:49-07:00 List-Id: On Friday, July 5, 2019 at 10:57:42 AM UTC+2, Per Jakobsen wrote: > I'm trying to demonstrate some of Ada's strengths with regard to low-level programming, and ran into the following issue: > > Having a byte-record consisting of bit-fields of different types (typical microcontroller register definitions). Compiling the below Ada code using avr-ada 1.2.2 (avr-gnat 4.9.3) gives some odd assembly code. > > Summary: > All assignments is really constants that ought to be calculated in full at compile time. > > 1) Clearing all bitfields in the byte as one assignment, it loads, clears and stores for each field even though the result is constant. *Very* inefficient and even dangerous if the bitfields are assumed to be set atomically!!! > > 2) Setting one field (any), a calculated byte constant is stored directly. > > 3) Setting more than one field, a calculated byte constant is initialized in SRAM and used during execution. Inefficient. > > 4) Clearing a non-composite byte is done directly. > > 5) Setting a non-composite byte is done directly. > > > Is there an option or pragma I need to set, or is this something more fundamental with the compiler? > First of all you are using an old compiler... Maybe upgrading the compiler (if possible) would help. I would (in the following order): 1) declare the registers as Atomic (or Atomic and Volatile but that doesn't matter as Atomic implies Volatile). 2) define constants for the values you are assigning. Regards, Mark L