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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Odd AVR-Ada code generation issue with constant record type Date: Tue, 09 Jul 2019 16:30:52 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="f796d8ceb5e5f014ffe5dc1a10ac4784"; logging-data="31431"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RbKaaEzAeYe/57OXaSl1LmLwxV8NtE90=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (darwin) Cancel-Lock: sha1:LT3CeAX3dGrGa4d42xx51KQ1muY= sha1:uyge4p7z+EK2R3yGR6f7RVWzkAA= Xref: reader01.eternal-september.org comp.lang.ada:56835 Date: 2019-07-09T16:30:52+01:00 List-Id: I don't have access to an up-to-date AVR compiler, so I had a go with GCC 9.1 compiling for cortex-m4. There's a big improvement using Volatile_Full_Access rather than just Volatile. This code ======================================================================== with System; with Interfaces; procedure Main is use Interfaces; type Enum_Type is (B00, B01, B10, B11); for Enum_Type use (B00 => 0, B01 => 1, B10 => 2, B11 => 3); type List_Type is array (0 .. 4) of Boolean with Pack; type Reg_Type is record Enum : Enum_Type; Bool : Boolean; List : List_Type; end record; for Reg_Type use record Enum at 0 range 6 .. 7; Bool at 0 range 5 .. 5; List at 0 range 0 .. 4; end record; for Reg_Type'Size use 8; -- Reg_A -- Reg_A : Reg_Type with Volatile_Full_Access, Address => System'To_Address (16#7a#); -- Reg_B -- Reg_B : Reg_Type with Volatile_Full_Access, Address => System'To_Address (16#7b#); -- Reg_C -- Reg_C : Reg_Type with Volatile_Full_Access, Address => System'To_Address (16#7c#); -- Reg_D -- Reg_D : Unsigned_8 with Volatile_Full_Access, Address => System'To_Address (16#7d#); -- Reg_E -- Reg_E : Unsigned_8 with Volatile_Full_Access, Address => System'To_Address (16#7e#); begin -- Set composite with resulting zero-byte. Reg_A := (Enum => B00, Bool => False, List => (others => False)); -- Set composite with resulting non-zero-byte (any one field is set, others zero). Reg_B := (Enum => B00, Bool => True, List => (others => False)); -- Set composite with resulting non-zero-byte (multiple fields is set). Reg_C := (Enum => B11, Bool => True, List => (others => True)); -- Clear Unsigned_8 directly. Reg_D := 16#00#; -- Setting Unsigned_8 directly. Reg_E := 16#FF#; end Main; ======================================================================== compiled with -O2 yields ======================================================================== Disassembly of section .text.startup._ada_main: 00000000 <_ada_main>: 0: 4b0a ldr r3, [pc, #40] ; (2c <_ada_main+0x2c>) 2: 4a0b ldr r2, [pc, #44] ; (30 <_ada_main+0x30>) 4: 480b ldr r0, [pc, #44] ; (34 <_ada_main+0x34>) 6: 217a movs r1, #122 ; 0x7a 8: b410 push {r4} a: 781c ldrb r4, [r3, #0] c: 700c strb r4, [r1, #0] e: 237b movs r3, #123 ; 0x7b 10: 7812 ldrb r2, [r2, #0] 12: 701a strb r2, [r3, #0] 14: 227c movs r2, #124 ; 0x7c 16: 7800 ldrb r0, [r0, #0] 18: 7010 strb r0, [r2, #0] 1a: 217d movs r1, #125 ; 0x7d 1c: 237e movs r3, #126 ; 0x7e 1e: 2000 movs r0, #0 20: 22ff movs r2, #255 ; 0xff 22: 7008 strb r0, [r1, #0] 24: 701a strb r2, [r3, #0] 26: f85d 4b04 ldr.w r4, [sp], #4 2a: 4770 bx lr ========================================================================