You copied the Doc URL to your clipboard.

Why do I Get the Error #2529 When Passing Variables to Intrinsics as Parameters?

Article ID: 162440625

Published date: 13 Feb 2018

Last updated: -

Applies to: ARM Compiler 5

Problem/Question

Why do I get the Error #2529 when passing variables to intrinsics as parameters?

Scenario

N/A

Answer

In ARM Compiler 5, compiler intrinsics have the appearance of a function call in C or C++. These intrinsics are replaced by a specific sequence of low-level instructions during compilation. For example, the __ssat() intrinsic inserts an SSAT instruction into the instruction stream generated by the compiler.

Although all intrinsics have function prototypes, some intrinsics cannot accept variables as input parameters. The reason for this limitation is that some intrinsics have at least one parameter that has a value that is encoded into the final OPCODE during compilation. This has the following implication:

  • Only a constant value is accepted.

  • The value must fall into a given range, depending on the number of the bits used for the constant value encoding.

For example, the __ssat() intrinsic has the following function prototype:

int __ssat(int val, unsigned int sat);

where val is the value to be saturated and sat is the bit position to saturate.

The __ssat() intrinsic is translated to the SSAT instruction. For one parameter, sat , the value is encoded into a 5-bit unsigned integer as part of the OPCODE. As a result, the intrinsic accepts only a constant integer ranging from 0 to 31 as the second parameter.

Example

The following example shows you the cause of the Error #2529.

#include <stdio.h>

#include <dspfns.h>

int main(void)

{

int val = 10097;

unsigned int sat = 4; //This needs to be a constant declaration

//rather than a variable.

printf("Before __ssat, val = %d\n", val);

val = __ssat(val, sat);

printf("After __ssat, val = %d\n", val);

}

Compile the example and you get an error message:

$ armcc hello_ssat.c --cpu=7-A

"hello_ssat.c", line 10: Error: #2529: expression must be an integral constant in range 1 to 32

val = __ssat(val, sat);

^

hello_ssat.c: 0 warnings, 1 error

To correct the code, change the following line in the example:

unsigned int sat = 4;

to:

const unsigned int sat = 4;

Compile the revised example and you get the result:

$ armcc hello_ssat.c --cpu=7-A

$ runner.pl --cpu cortex-a8 --image __image.axf

Before __ssat, val = 10097

After __ssat, val = 7

Workaround

N/A

Example

N/A

Related Information

None.

Was this page helpful? Yes No