From: Simon Wright <simon@pushface.org>
Subject: Re: Odd AVR-Ada code generation issue with constant record type
Date: Tue, 09 Jul 2019 16:30:52 +0100
Date: 2019-07-09T16:30:52+01:00 [thread overview]
Message-ID: <lya7dn6x8z.fsf@pushface.org> (raw)
In-Reply-To: b78a975c-8ef1-41ac-b4c2-c1c07675765a@googlegroups.com
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
========================================================================
next prev parent reply other threads:[~2019-07-09 15:30 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
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 [this message]
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