On Fri, 22 May 2009, Szak�ts Viktor wrote:

Hi,

> It's common practice in Clipper/Harbour to use arrays to "emulate" structures:
> ---
> #define _STRU_xVAR1  1
> #define _STRU_xVAR2  2
> #define _STRU_MAX_
> LOCAL stru[ _STRU_MAX_ ]
> stru[ _STRU_xVAR1 ] := 100
> ? stru[ _STRU_xVAR1 ]
> ---
> In these scenarios, the array is indexed with a constant
> in almost all cases.
> This, currently, generates this pcode:
> ---
>       HB_P_PUSHBYTE, 100,     /* 100 */
>       HB_P_PUSHLOCALNEAR, 1,  /* STRU */
>       HB_P_ONE,
>       HB_P_ARRAYPOP,
> 
>       HB_P_PUSHFUNCSYM, 1, 0, /* QOUT */
>       HB_P_PUSHLOCALNEAR, 1,  /* STRU */
>       HB_P_ONE,
>       HB_P_ARRAYPUSH,
> ---
> I wonder if we could optimize it by using one indexed
> array pop opcode:
> ---
>       HB_P_PUSHBYTE, 100,     /* 100 */
>       HB_P_ARRAYPOPINDEX, 1,
>       HB_P_PUSHFUNCSYM, 1, 0, /* QOUT */
>       HB_P_ARRAYPUSHINDEX, 1,
> ---
> Since these kind of lines may appear in mass, such optimization
> may result in code size reduction and speed increase.

Yes, it will give some speed improvement but please remember that
we have limited PCODE list. Such problem does not exist in -gc3
output because we can use unlimited list of functions and such
code is already optimized. Just look at code generated when -gc3
is used and hb_xvmArrayItemPush()/hb_xvmArrayItemPop().

best regards,
Przemek
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to