c - gcc optimization, const static object, and restrict -


I am working on an embedded project and I am trying to add more structure to some code, which is the macro Use USARTs to optimize access to registers I want to organize the preprocessor. Define the register address in the #structure structure. If I define as the compound Litrls the structures in a macro and extend to them inline functions, the GCC is adequately bypass pointer in the smart, generated assembly and assumes direct member of structure hardcoded address. Ex .:

C-1:

  Strait Yuet {fluctuations uint8_t * Ukera, * Usisarbi * Usisarsi * Uder; Voltile UIT 16_T * urr; }; #define M_yuetiaks (x) \ ((structure Uart) {\ Kkyusra = & amp; Usisar ## x ## A, Uarsarbi = and Usisar ## X # B, \ Kukesarsi = and Usisar ## x # C, \ .ubrr = & amp; UBRR ## X, \ .udr = and amp; UDR ## X \}) invalid inlined_func (const struct uart * p, other_args ...) {... (* p -> Eucla) = 0; (* P-> ucsrb) = 0; (* P-> ucsrc) = 0; } ... int main () {... inlined_func (& amp; m_URST (0), other_pairs ...); ...}  

here UCSR0A, UCSR0B, & amp; C, is defined as the L-value as the U-registry, such as

  #define UCSR0A (* (Uint8_t *) 0xFFFF)  

The GCC was able to completely eliminate the structure, and to write all the tasks shown in inlineline_funk () directly to the register address, read the register address in w / o machine register, and indirectly address Happened:

A1:

  movb $ 0, UCSR 0 a movb $ 0, UCSR 0b movb $ 0, UCSR0C   

It writes value directly Yuesarart registers, for w / o address to load the register machine, and therefore the object file does not need to literally occurring at all. Structure literally becomes a compile-time structure, in which the code generated for the abstract does not have any cost.

I was getting rid of the use of macros, and tried to use a stable still structure:

C2:

  #define M_UART0 M_UARTX (0) #define M_UART1 M_UARTX (1) static constitution structure * const uart [2] = {& amp; M_UART0, & Amp; M_UART1}; .... int main () {... inlined_func (UAT [0], other_pairs ...); ...}  

However, the GCC can not completely remove the structure here:

A2:

  movl __compound_literalk0% Aaksaks Mbibi $ 0,% (AX) walk __compound_laitral 2.0 + 4% Aaksajimbibi $ 0,% (AX) Movl __kanpound_laitral 2.0 + 8% Aaksajimbibi $ 0,% (AX)  

This loads the register address in a machine register, and uses the indirect address to write the register. Does anybody know that I can understand the GCC to generate the A1 assembly code for the CC-C code? I have tried different uses of __restricted modifier without any profit.

After many years of experience with UATS and USARs, I have come to the conclusion:

Do not use struct for maping 1: 1 mapping with URT registers.

Add padding between the compiler struct members without your knowledge, thus messing up 1: 1 correspondence.

Writing the UART registers is best done or through a function.

Remember to use the variable modifier while defining points to the registers.

Very low performance benefits with assembly language

The assembly language should be used only when UART is accessed through processor ports instead of memory-map. There is no support for Sea Languages ​​for ports, it is very efficient to reach UART registers through pointers (create and verify an assembly language list). Occasionally code may take more time in assembly.

Separate UAT functionality in different libraries

This is a good candidate. In addition, once the code has been tested, it may not have libraries compiled at all times goes.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -