 |
|
 |
RENESAS TOOL NEWS [July 16, 2003: RSO-M3T-NC30WA-030716D]
|
A Note on Using C Compiler M3T-NC30WA
|
Please take note of the following problem in using the M3T-NC30WA C compilers (with an integrated development environment):
- On multiplying a scalar-type variable by an immediate value
- Versions Concerned
- M3T-NC30WA V.4.00 Release 1 through V.5.10 Release 1
- for the M16C/60, M16C/30, M16C/20, and M16C/10 series MCUs
- Description
Multiplying a scalar-type variable by an immediate value may result in incorrect code being generated.
- Conditions
- This problem occurs if the following five conditions are satisfied:
| (1) | Any one or more of these optimizing options, -O, -O1, -O2, -O3, -O4, -O5, -OR, and -OS, is selected. |
| (2) | A multiplication of a scalar-type auto variable, A, by an immediate value is performed, and its result is stored in another variable, B. |
| (3) | A register is allocated to variable A and memory to variable B. |
| (4) | Either or both of variable A and the immediate value in (2) are cast to the type of variable B. |
| (5) | The types of variables A and B are as follows:
| Variable A: | unsigned int, signed int, unsigned short, or signed short |
| Variable B: | unsigned long or signed long |
|
- Example
--------------------------------------------------------
void func(void)
{
long l;
int i;
:
l = (long)i * 100; /* Conditions (2) and (4) */
l += (long)i; /* NOTE */
:
}
--------------------------------------------------------
NOTE: The code that cannot correctly refer to the value of variable i is generated.
- Workaround
- This problem can be circumvented by performing the following steps:
| (1) | Define a temporary auto variable and assign the immediate value in Condition (2) to it. |
| (2) | Place a dummy asm function immediately after the assignment expression in (1) above. |
| (3) | Use the temporary auto variable defined in (1) in place of the immediate value in Condition (2). |
Example:
--------------------------------------------------------
void func(void)
{
int tmp = 100; /* A tmp auto variable defined and
an immediate value assigned to it */
asm(); /* A dummy asm function placed */
:
l = (long)i * tmp; /* Use tmp in place of 100 */
:
}
--------------------------------------------------------
- Schedule of Fixing the Problem
We plan to fix this problem in our next release of the product.
|
 |