 |
|
 |
RENESAS TOOL NEWS on May 16, 2004: RSO-M3T-NC30WA-040516D
A Note on Using C-Compiler Package M3T-NC30WA
--On if Statements Including Bitwise Operations--
|
Please take note of the following problem in using the M3T-NC30WA C-compiler
package (with assembler and integrated development environment) for the
M16C/60, M16C/30, M16C/Tiny, M16C/20, M16C/10, and R8C/Tiny series MCUs:
- On if statements including bitwise operations
- Versions Concerned
M3T-NC30WA V.1.00 Release 1 through V.5.30 Release 1
- Description
When the result of the bitwise operation between a variable and an
immediate value is contained in the controlling expression of an if
statement, the if statement may be evaluated incorrectly.
- 2.1 Conditions
- This problem occurs if the following six conditions are satisfied all:
| (1) |
One or more optimizing options are selected out of -O1, -O2, -O3,
-O4, -O5, -O, -OR, and -OS |
| (2) |
In the program exist an if statement whose controlling expression
contains the result of the bitwise operation between a variable
and an immediate value.
This controlling expression is either of the following:
(a) "a variable & an immediate value"
(b) "(a variable & an immediate value) != 0" |
| (3) |
The variable in (2) is 16 bits long. |
| (4) |
The lower 8 bits of the immediate value in (2) are all 0s. |
| (5) |
After compilation the variable in (2) is assigned to register R2, R3, A0, or A1. |
| (6) |
The program statement executed when the evaluation of the if
statement is TRUE is only an expression where an immediate value
is assigned to a variable. |
- 2.2 Example
----------------------------------------------------------------
unsigned char c;
void func(void)
{
unsigned int g; /* Condition (3) */
if(( g & 0xff00 ) != 0) /* Conditions (2) and (4) */
data = 1; /* Condition (6) */
}
----------------------------------------------------------------
- Workaround
Place a dummy asm function in front of the program statement when the
evaluation of the if statement is TRUE.
------------------------------------------------------------------
unsigned char c;
void func(void)
{
unsigned int g;
if(( g & 0xff00 ) != 0){
asm(""); /* dummy asm function */
data = 1;
}
}
------------------------------------------------------------------
- Schedule of Fixing the Program
We plan to fix this program in our next release of the product.
|
 |