comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Lorenzen <mark.lorenzen@gmail.com>
Subject: Re: Odd AVR-Ada code generation issue with constant record type
Date: Fri, 5 Jul 2019 02:24:49 -0700 (PDT)
Date: 2019-07-05T02:24:49-07:00	[thread overview]
Message-ID: <eba484e8-9eb1-4240-9dbf-0bfacfc4874a@googlegroups.com> (raw)
In-Reply-To: <b78a975c-8ef1-41ac-b4c2-c1c07675765a@googlegroups.com>

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


  reply	other threads:[~2019-07-05  9:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-05  8:57 Odd AVR-Ada code generation issue with constant record type Per Jakobsen
2019-07-05  9:24 ` Mark Lorenzen [this message]
2019-07-05 12:19 ` Per Jakobsen
2019-07-08 14:49   ` Stéphane Rivière
2019-07-09 12:12 ` Per Jakobsen
2019-07-09 15:30 ` Simon Wright
2019-07-09 18:10 ` Per Jakobsen
2019-07-09 18:46 ` Per Jakobsen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox