comp.lang.ada
 help / color / mirror / Atom feed
From: MatthiasR <MatthiasR@invalid.invalid>
Subject: Re: Forcing GNAT to use 32-bit load/store instructions on ARM?
Date: Sun, 20 Jul 2014 13:35:56 +0200
Date: 2014-07-20T13:35:56+02:00	[thread overview]
Message-ID: <lqg9ve$svj$1@dont-email.me> (raw)
In-Reply-To: lpf7hv$am9$1@loke.gir.dk

Randy Brukardt wrote:

> [...]
> 
>> Unfortunately there seem to be no way to force a specific access width,
>> so this feature is not really useable (without the mentioned workaround
>> with the temporary variable) on architectures where the allowed access
>> width is not uniform over the whole address range.
> 
> No, you're looking at this the wrong way. If you write this in C, you read
> the entire register and then do some sort of bit-mask, and then write the
> thing back. You have to do that same thing in Ada, just using the record
> type instead of the bit mask. Ada replaces the bit masking operations by
> more readable record component accesses; it doesn't suddenly allow you to
> write something that you couldn't possibly write in C [a direct write of
> part of a register]. (Whether Ada *should* have allowed you do to that is
> a totally different question and relatively irrelevant at the moment
> because the language isn't likely to support anything new in the near
> future.)
> 
>                                                    Randy.

Ironically, there *is* another possibility, just in C. In principle, 
'Volatile Bitfields', mapped to the register via a pointer, can be used.

Bitfields are avoided by most C programmers because their layout is 
generally not well defined. Means to control the layout (like representation 
clauses in Ada) do not exist.

At least for the ARM platform, the situation is more convenient:
There are rules for the layout of bitfields given in the AAPCS (ABI 
specification for ARM, 'Procedure Call Standard for the ARM Architecture').
So, if the compiler is AAPCS-compliant, the layout of the bitfield records 
is exactly defined.

Additionaly, the AAPCS requires in chapter 7.1.7.5 
(http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf)
that all reads or writes from/to volatile bitfields must be done 'using the 
access width appropriate to the type of the container'.

The 'container' is not the record/struct as a whole, it is a type specifier 
given with each of the bitfields (this concept of a 'container type' is 
somewhat strange, I needed some time to get the idea of this...)

Example:

struct s 
{
  volatile int a:8;
  volatile char b:2
};

'int' and 'char' are the 'container types' of the bitfields 'a' and 'b'. A 
AAPCS-compliant compiler must read or write 's.a' using a 32-bit access 
(assuming 'int' is 32 bit wide). Accesses to 's.b' must be 8 bit wide.

So, if a C compiler is AAPCS-compliant, volatile bitfields should have the 
desired behaviour. Whether a compiler is *really* AAPCS-compliant, is 
another question. A well-known open source C compiler had bugs in this area 
in several releases. Last year, attempts were made to repair it. I don't 
know the current status.

Matthias



  parent reply	other threads:[~2014-07-20 11:35 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-30 22:11 Forcing GNAT to use 32-bit load/store instructions on ARM? daniel.dmk
2014-06-30 23:41 ` Jeffrey Carter
2014-07-01 12:06   ` Simon Clubley
2014-07-01 15:44     ` Niklas Holsti
2014-07-01 17:26       ` Simon Clubley
2014-07-01 17:18     ` Simon Wright
2014-07-01 19:43       ` Simon Wright
2014-07-01 17:28     ` Jeffrey Carter
2014-07-01  0:55 ` anon
2014-07-01  4:30 ` Niklas Holsti
2014-07-01  8:11 ` Dmitry A. Kazakov
2014-07-01 12:09   ` Simon Clubley
2014-07-01 12:20     ` Dmitry A. Kazakov
2014-07-01 17:00       ` Simon Clubley
2014-07-01 19:36         ` Dmitry A. Kazakov
2014-07-01 20:08           ` Simon Clubley
2014-07-02 22:24             ` Randy Brukardt
2014-07-06 20:40               ` MatthiasR
2014-07-07  0:25                 ` Simon Clubley
2014-07-07 22:38                 ` Randy Brukardt
2014-07-08  6:51                   ` Simon Wright
2014-07-10 11:47                     ` Simon Wright
2014-07-10 13:06                       ` Simon Clubley
2014-07-11 18:05                         ` Simon Wright
2014-07-11 20:22                           ` Simon Clubley
2014-07-08  8:50                   ` Brian Drummond
2014-07-08 12:12                   ` Simon Clubley
2014-07-08 13:26                     ` G.B.
2014-07-08 17:13                       ` Simon Clubley
2014-07-08 15:36                     ` Adam Beneschan
2014-07-08 15:40                       ` Adam Beneschan
2014-07-08 20:34                     ` Randy Brukardt
2014-07-09  7:31                       ` Dmitry A. Kazakov
2014-07-10  0:11                         ` Simon Clubley
2014-07-20 11:35                   ` MatthiasR [this message]
2014-07-20 15:49                     ` Simon Clubley
2014-07-26 11:05                       ` MatthiasR
2014-08-10 11:20                         ` MatthiasR
2014-07-01 12:03 ` Simon Clubley
2014-07-01 19:52   ` daniel.dmk
2014-07-01 20:40     ` Simon Clubley
2014-07-01 20:55       ` Simon Clubley
2014-07-01 21:01       ` Niklas Holsti
2014-07-01 21:20         ` Simon Clubley
2014-07-01 22:38           ` Niklas Holsti
2014-07-02 16:49             ` Simon Clubley
2014-07-01 21:55         ` daniel.dmk
2014-07-02  7:30     ` Simon Wright
2014-07-02 18:52       ` daniel.dmk
2014-07-04 23:51       ` Niklas Holsti
2014-07-05  0:18         ` Niklas Holsti
replies disabled

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