comp.lang.ada
 help / color / mirror / Atom feed
From: Tomas Cernaj <tcernaj.WITHOUTTHIS@gmx.de>
Subject: Access to fixed memory location
Date: 30 Nov 2007 19:32:29 GMT
Date: 2007-11-30T20:32:29+01:00	[thread overview]
Message-ID: <4750654d$0$13115$9b4e6d93@newsspool2.arcor-online.net> (raw)

Hello everyone,

is there any way to tell the Ada compiler that an Address attribute 
should be constant? I want to use it for accessing fixed memory 
locations, and without the Address attribute being constant the compiler 
won't optimize away an indirect access.

I couldn't find anything in the RM or GNAT documentation... The point is 
that I want to use the 'Address construct on the AVR target, which is an 
8-bit processor, so the indirect access is quite expensive.

I suppose that was a bit unclear, so here's an example: :)
I have the following declarations in a package spec file:

    type T_Type is array (0 .. 7) of Boolean;
    pragma Pack (T_Type);
    for T_Type'Size use 8;
    
    package TA is new System.Address_To_Access_Conversions (T_Type);
    X : constant access T_Type
        := TA.To_Pointer (System.Storage_Elements.To_Address (50));
    
    Y : T_Type;
    for Y'Address use System.Storage_Elements.To_Address (51);
    pragma Import (Ada, Y);

Note that X is something like a "T_Type * const X" in C.
Compiling the following code

        X (4) := True;
        Y (5) := True;

with GNAT (gcc-4.2 -O -S) yields this assembler output (x86-64):

        orb     $16, 50			; X (4) := True
        movq    testpkg__y(%rip), %rdx	; Y (5) := True
        movzbl  (%rdx), %eax
        orl     $32, %eax
        movb    %al, (%rdx)

That's because the compiler can not assume that Y'Address will not be 
changed.

Thank you for your help,
Tomas



             reply	other threads:[~2007-11-30 19:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-30 19:32 Tomas Cernaj [this message]
2007-11-30 21:42 ` Access to fixed memory location Samuel Tardieu
2007-11-30 22:22   ` Samuel Tardieu
2007-12-02 22:00   ` Tomas Cernaj
2007-12-02 23:13     ` Samuel Tardieu
replies disabled

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