Tool News
 
 
 

Tool News

Products Info
Downloads
Tools FAQs
MAEC TOOL NEWS: MAECT-M3T-CC32R-020716D

A Note on Cross-Tool Kit
M3T-CC32R

Please take note of the following problem in using cross-tool kit M3T-CC32R for the M32R family MCUs:
  • On programs containing a remainder operator (%) or remainder assignment operator (%=) with a divisor of 0x80000000 or -0x80000000 (see note.)
note: In C language, integer constant -0x80000000 must be expressed as -0x7FFFFFFFF-1. In this news, however, the former representation is used for understandability, except for examples of programming.


  1. Versions Concerned
    M3T-CC32R V.1.00 Release 1 -- V.3.20 Release 1

  2. Description
    Compiling programs containing a remainder operator (%) or remainder assignment operator (%=) with a divisor of 0x80000000 or -0x80000000 causes the following internal error to appear:
    error: code template illegal number '2147483648'
    2.1 Conditions
    This problem occurs if the following three conditions are satisfied:
    (1) A program contains a remainder operator (%) or remainder assignment operator (%=).
    (2) The dividend in (1) is not a constant but an integral expression, that is, an integral expression containing variables etc.
    (3) The combination of the dividend and divisor in (1) is any of the following:
    (a) The dividend is unsigned, and the divisor is -0x80000000.
    (b) The dividend is unsigned, and the divisor is 0x80000000.
    (c) The dividend is signed, and the divisor is 0x80000000.

    2.2 Examples
    [sample1.c]
    --------------------------------------------------------------------
    unsigned long var1;                  /* Condition (3)(a) */
    void foo(void)
    {
        var1 %= (-0x7FFFFFFF-1);   /* Conditions (1), (2), and (3)(a) */
    }
    --------------------------------------------------------------------
    
    [sample2.c]
    --------------------------------------------------------------------
    long var1, var2;                    /* Condition (3)(c) */
    void foo(void)
    {
        var1 = (var2 - 1) % 0x80000000; /* Conditions (1), (2), and (3)(c) */
    }
    --------------------------------------------------------------------
    
    [sample3.c]
    --------------------------------------------------------------------
    unsigned long var1;
    short var2;                          /* (3)(c) */
    void foo(void)
    {
        var1 = var2 % 0x80000000;   /* Conditions (1), (2), and (3)(c) */
    }
    --------------------------------------------------------------------
    
    Examples of typing commands in M3T-CC32R (a % sign denotes a prompt): 
    --------------------------------------------------------------------
    % cc32R -c sample1.c
    % cc32R -c sample2.c
    % cc32R -c sample3.c
    --------------------------------------------------------------------
  3. Workaround
    If the dividend is unsigned, use the method described in (1), otherwise in (2) below.
    (1) In the case where the dividend is unsigned
    Replace the remainder operator (%) with a bitwise AND operator (&) whose parameter is the absolute value of the current divisor minus 1. Also replace the remainder assignment operator (%=) with a bitwise AND assignment operator (&=) whose parameter is the absolute value of the current divisor minus 1.
    [Modification of sample1.c]
    ----------------------------------------------------------------
       unsigned long var1;
       void foo(void)
       {
           var1 &= 0x7FFFFFFF;     /* |-0x7FFFFFFF-1| - 1 */
       }
    ----------------------------------------------------------------
    (2) In the case where the dividend is signed
    As described in Condition (3) (c), the problem occurs only when a remainder operation is performed with the dividend being 0x80000000. This operation gives 0 when the dividend equals to -0x80000000 and otherwise gives the dividend itself. If the dividend is of type short or char, the result of the operation also becomes the dividend itself.
    Therefore, change this remainder operation to either of the following operations:
    (a) A conditional operation that gives 0 when the dividend is -0x80000000 and otherwise the dividend itself by using a conditional operator (? :).
    (b) No remainder operation (operation omitted) if the dividend is of type short or char.
    [Modification of sample2.c]
    --------------------------------------------------------------------
       long var1, var2;
       void foo(void)
       {
           long tmp;
           var1 = ((tmp = (var2 - 1)) == (-0x7FFFFFFF-1) ? 0 : tmp);
       }
    --------------------------------------------------------------------
    Note: In the above example, using variable tmp reduces the references
          of var2 to only once.
    
    [Modification of sample3.c]
    --------------------------------------------------------------------
       unsigned long var1;
       short var2;                         /* A dividend of type short */
       void foo(void)
       {
           var1 = var2;              /* The remainder operation omitted */
       }
    --------------------------------------------------------------------
  4. Schedule of Fixing the Problem
    We plan to fix this problem in our next release.




© 2008. Renesas Technology Corp., All rights reserved. Privacy | Legal