Keil Logo

NOALIAS Compiler Directive

Abbreviation

NOAL

Arguments

None.

Default

All write operations via pointer are destructive. The compiler does not reuse the contents of registers when variables are accessed through pointers.

µVision

Options — C166 — Alias Checking on Pointer Accesses.

Description

It is common practice for the compiler to copy a variable's value into a register for fast, temporary access. However, when the value is changed through a pointer to the variable, the contents of the register must be re-synchronized. The technique which does this is known as alias checking. It is enabled by default.

The NOALIAS directive instructs the compiler to ignore pointer write operations during the optimization phase. If a register holds a variable, the variable is reused, even when access through a pointer might have modified that variable.

If you are confident that certain functions in your program do not modify variables through pointers, the NOALIAS directive may be used to reduce program size.

Example
C166 SAMPLE.C NOALIAS

#pragma NOAL

The following example:

 stmt lvl     source
    1         struct { int  i1; int  i2; } *p_struct;
    2         int val;
    3
    4         void func1 (int *p_val)  {
    5  1        p_struct->i1 = val;
    6  1        *p_val = 0;
    7  1        p_struct->i2 = val;
    8  1      }
    9
   10         void func2 (void)  {
   11  1        func1 (&val);
   12  1      }

demonstrates code generated using the NOALIAS directive:

Code Generated
Without NOALIAS
; FUNCTION func1 (BEGIN  RMASK = @0x4030)
                   ; SOURCE LINE # 4
;---- 'p_val' assigned to 'R8' ----
                   ; SOURCE LINE # 5
0000 F2F40000 R    MOV       R4,p_struct
0004 84040200 R    MOV       [R4],val

                   ; SOURCE LINE # 6
0008 E005          MOV       R5,#00H
000A B858          MOV       [R8],R5
                   ; SOURCE LINE # 7
000C F2F50200 R    MOV       R5,val
0010 F2F40000 R    MOV       R4,p_struct
0014 C4540200      MOV       [R4+#02H],R5
                   ; SOURCE LINE # 8
0018 CB00          RET
; FUNCTION func1 (END    RMASK = @0x4030)

; FUNCTION func2 (BEGIN  RMASK = @0x0130)
                   ; SOURCE LINE # 10
                   ; SOURCE LINE # 11
001A E6F80200 R    MOV       R8,#val
001E BBF0          CALLR     func1
                   ; SOURCE LINE # 12
0020 CB00          RET
; FUNCTION func2 (END    RMASK = @0x0130)
CODE SIZE: 34 Bytes
Code Generated
With NOALIAS
; FUNCTION func1 (BEGIN  RMASK = @0x4070)
                   ; SOURCE LINE # 4
;---- 'p_val' assigned to 'R8' ----
                   ; SOURCE LINE # 5
0000 F2F40200 R    MOV       R4,val
0004 F2F60000 R    MOV       R6,p_struct
0008 B846          MOV       [R6],R4
                   ; SOURCE LINE # 6
000A E005          MOV       R5,#00H
000C B858          MOV       [R8],R5
                   ; SOURCE LINE # 7


000E C4460200      MOV       [R6+#02H],R4
                   ; SOURCE LINE # 8
0012 CB00          RET
; FUNCTION func1 (END    RMASK = @0x4070)

; FUNCTION func2 (BEGIN  RMASK = @0x0170)
                   ; SOURCE LINE # 10
                   ; SOURCE LINE # 11
0014 E6F80200 R    MOV       R8,#val
0018 BBF3          CALLR     func1
                   ; SOURCE LINE # 12
001A CB00          RET
; FUNCTION func2 (END    RMASK = @0x0170)
CODE SIZE: 28 Bytes

When the NOALIAS directive is used, the compiler does not reload p_struct or val, even though the *p_val = 0 statement destroys val.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.