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 — C251 — 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
C251 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)
                      ; SOURCE LINE # 4

;---- 'p_val' assigned to 'WR6' ----
                      ; SOURCE LINE # 5
000000 7E1500      R  MOV      WR2,val
000003 7E2500      R  MOV      WR4,p_struct
000006 1B2810         MOV      @WR4,WR2
                      ; SOURCE LINE # 6
000009 6D22           XRL      WR4,WR4
00000B 1B3820         MOV      @WR6,WR4
                      ; SOURCE LINE # 7
00000E 7E3500      R  MOV      WR6,val
000011 7E2500      R  MOV      WR4,p_struct
000014 59320002       MOV      @WR4+2,WR6
                      ; SOURCE LINE # 8
000018 22             RET
;       FUNCTION func1 (END)

;       FUNCTION func2 (BEGIN)
                      ; SOURCE LINE # 10
                      ; SOURCE LINE # 11
000000 7E340000    R  MOV      WR6,#WORD0 val
000004 120000      R  LCALL    func1
                      ; SOURCE LINE # 12
000007 22             RET
;       FUNCTION func2 (END)
CODE SIZE: 33 Bytes
Code Generated
With NOALIAS
;       FUNCTION func1 (BEGIN)
                      ; SOURCE LINE # 4
000000 7D13           MOV      WR2,WR6
;---- 'p_val' assigned to 'WR2' ----
                      ; SOURCE LINE # 5
000002 7E3500      R  MOV      WR6,val
000005 7E2500      R  MOV      WR4,p_struct
000008 1B2830         MOV      @WR4,WR6
                      ; SOURCE LINE # 6
00000B 6D00           XRL      WR0,WR0
00000D 1B1800         MOV      @WR2,WR0
                      ; SOURCE LINE # 7


000010 59320002       MOV      @WR4+2,WR6
                      ; SOURCE LINE # 8
000014 22             RET
;       FUNCTION func1 (END)

;       FUNCTION func2 (BEGIN)
                      ; SOURCE LINE # 10
                      ; SOURCE LINE # 11
000000 7E340000    R  MOV      WR6,#WORD0 val
000004 120000      R  LCALL    func1
                      ; SOURCE LINE # 12
000007 22             RET
;       FUNCTION func2 (END)
CODE SIZE: 29 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.