Hi Dmitry,

Hmmm. I just tried a couple of examples myself which look OK. It seems the problem must be something more specific than just being over 128 bytes. I won't have access to the code that caused me problem for a couple of days. I will post an example that illustrates the problem later in the week.

Regards,
Steve


Dmitry wrote:

Steve,
at least the following code
struct __S {
 char a[64],b[64];
 int c[13];
};
struct __S *s;
struct __S * r(int i)
{
   return s+i;
}


being evaluated to

       .text
       .p2align 1,0
.global _r
       .type   _r,@function
/***********************
* Function `_r'
***********************/
_r:
/* prologue: frame size = 0 */
.L__FrameSize_r=0x0
.L__FrameOffset_r=0x2
       push    r10
/* prologue end (size=1) */
       mov     r15, r10         ;  12  *movhi3/5       [length = 1]
       mov     #llo(154), r12   ;  13  *movhi3/8       [length = 2]
       call    #__mulhi3        ;  14  *mulhi3_call    [length = 2]
       mov     r14, r15         ;  15  *movhi3/5       [length = 1]
       add     &s, r15  ;  16  *addhi3_3/5     [length = 2]
/* epilogue: frame size=0 */
       pop     r10
       ret
/* epilogue end (size=2) */
/* function r size 11 (8) */
.Lfe1:
       .size   _r,.Lfe1-_r
/********* End of function ******/

       .comm s,2,2


which seems to be correct...

Actually, multiplication vs. shifts&adds/subs being used upon max number of iterations necessary for offset computation. For example, if a structure size if 90, the multiplier being used to compute indexing offset.

In general the decision about shifts&adds vs. multiplier is the following:

if total_sifts_and_adds_operations*operand_size_in_bytes > some_threshold then use multiplier otherwise use shifts and tricks.
some_threshold == 10 now

for example :
        a = b*65;
requires 6 shifts and 1 add operations.


cheers,
~d



On Tuesday 25 May 2004 16:22, Dmitry wrote:
Hi Steve,
Hm....
Multiplier produces incorrect result?
Or just an assembly output tricks registers?
I had no probs with such structures...

~d




-----Original Message-----
From: mspgcc-users-ad...@lists.sourceforge.net
[mailto:mspgcc-users-ad...@lists.sourceforge.net] On Behalf Of Steve
Underwood
Sent: Tuesday, May 25, 2004 3:52 PM
To: mspgcc-users@lists.sourceforge.net
Subject: [Mspgcc-users] compiler bug

Hi Dimitry,

I found a problem with the compiled code for GCC 3.2.3.

If a structure is less than or equal to 128 bytes, an array of
structures is accessed using shifts and adds to calculate the offset
into the array. However, if the structure is more than 128 bytes the
multiplier is used for these calculations. When shifts and adds are
being used things work OK. When the multiplier is used the offset is
calculated incorrectly.

Regards,
Steve


Reply via email to