From 9526552410bc120178bef3d2a97bcb126decf338 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 14 Aug 2006 13:03:42 +0000 Subject: [PATCH] 2006-08-14 14:22 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/TODO - removed eliminating hb_stackTopItem() from TOFIX - Done. * harbour/include/hbexprc.c * restore original expression type after *POPEQ optimization * harbour/source/compiler/harbour.c * removed some commented code * harbour/source/compiler/harbour.y % optimized PCODE generated for FOR/NEXT statement - it eliminates one unconditional jump inside the loop - Ryszard if you can please check me. --- harbour/ChangeLog | 15 +++ harbour/TODO | 10 -- harbour/include/hbexprc.c | 7 +- harbour/source/compiler/harbour.c | 178 ------------------------------ harbour/source/compiler/harbour.y | 27 +++-- 5 files changed, 36 insertions(+), 201 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a904fdf1e8..ecb5a7ccfd 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,21 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2006-08-14 14:22 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/TODO + - removed eliminating hb_stackTopItem() from TOFIX - Done. + + * harbour/include/hbexprc.c + * restore original expression type after *POPEQ optimization + + * harbour/source/compiler/harbour.c + * removed some commented code + + * harbour/source/compiler/harbour.y + % optimized PCODE generated for FOR/NEXT statement - it eliminates + one unconditional jump inside the loop - Ryszard if you can please + check me. + 2006-08-14 10:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/rtl/fserror.c + added translation error code for ENMFILE diff --git a/harbour/TODO b/harbour/TODO index f279915292..7159c4faba 100644 --- a/harbour/TODO +++ b/harbour/TODO @@ -180,16 +180,6 @@ Status...: Open. ======================================================================= -Assign to: Przemek -Detail...: Eliminate using hb_stackTopItem() it causes that HVM is not - safe for reentrant and automatic GC activation. To not - reduce the speed chance the indexes in HB_STACK structure to - give fastest access to the most last allocated item on the - stack. -Status...: Open. - -*** - Assign to: Przemek Detail...: Fix setting private base for code blocks created by macro compiler. Maybe it should be bound with making CLEAR MEMORY diff --git a/harbour/include/hbexprc.c b/harbour/include/hbexprc.c index a5c80f0d91..3d27ffb088 100644 --- a/harbour/include/hbexprc.c +++ b/harbour/include/hbexprc.c @@ -308,7 +308,7 @@ void hb_compExprUseOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) if( ! ( iScope == HB_VS_LOCAL_FIELD || iScope == HB_VS_GLOBAL_FIELD ) ) { - HB_EXPRTYPE iType = pSelf->value.asOperator.pRight->ExprType; + HB_EXPRTYPE iType = pSelf->value.asOperator.pRight->ExprType, iOldType; if( iType == HB_ET_NUMERIC || iType == HB_ET_STRING ) { @@ -332,6 +332,7 @@ void hb_compExprUseOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) } } /* NOTE: direct type change */ + iOldType = pSelf->value.asOperator.pLeft->ExprType; pSelf->value.asOperator.pLeft->ExprType = HB_ET_VARREF; HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_PCODE ); @@ -352,6 +353,7 @@ void hb_compExprUseOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) break; } HB_EXPR_GENPCODE1( hb_compGenPCode1, bOpEq ); + pSelf->value.asOperator.pLeft->ExprType = iOldType; return; } else if( pSelf->value.asOperator.pRight->ExprType == HB_ET_VARIABLE ) @@ -361,6 +363,7 @@ void hb_compExprUseOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) if( ! ( iScope == HB_VS_LOCAL_FIELD || iScope == HB_VS_GLOBAL_FIELD ) ) { /* NOTE: direct type change */ + iOldType = pSelf->value.asOperator.pLeft->ExprType; pSelf->value.asOperator.pLeft->ExprType = HB_ET_VARREF; pSelf->value.asOperator.pRight->ExprType = HB_ET_VARREF; HB_EXPR_USE( pSelf->value.asOperator.pLeft, HB_EA_PUSH_PCODE ); @@ -381,6 +384,8 @@ void hb_compExprUseOperEq( HB_EXPR_PTR pSelf, BYTE bOpEq ) break; } HB_EXPR_GENPCODE1( hb_compGenPCode1, bOpEq ); + pSelf->value.asOperator.pLeft->ExprType = iOldType; + pSelf->value.asOperator.pRight->ExprType = iType; return; } } diff --git a/harbour/source/compiler/harbour.c b/harbour/source/compiler/harbour.c index 344479e068..efcbe78f7e 100644 --- a/harbour/source/compiler/harbour.c +++ b/harbour/source/compiler/harbour.c @@ -2676,36 +2676,6 @@ static void hb_compPrepareOptimize( void ) ULONG hb_compGenJump( LONG lOffset ) { - /* - * optimizing jumps here by shorting them and setting HB_P_NOOPs - * only slow down the compilation process for three reasons: - * 1. When it's dummy jump to next instruction we need two passes - * in hb_compOptimizeJumps() to fully remove it - * 2. hb_compOptimizeJumps() also make jump shortcutting in each pass - * 3. When Jump Optimization is disabled (-kJ) then it cause slowness - * at runtime because we will have more HVM loops: first for the - * shorter jump and next for the HB_P_NOOP PCODE(s) - * [druzuz] - */ -#if 0 - /* Just a place holder, it might be a far jump...*/ - if( lOffset == 0 ) - { - hb_compGenPCode4( HB_P_JUMPFAR, 0, 0, 0, ( BOOL ) 1 ); - } - else if( HB_LIM_INT8( lOffset ) ) - { - hb_compGenPCode4( HB_P_JUMPNEAR, HB_LOBYTE( lOffset ), HB_P_NOOP, HB_P_NOOP, ( BOOL ) 1 ); - hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 2 ); - hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 1 ); - } - else if( HB_LIM_INT16( lOffset ) ) - { - hb_compGenPCode4( HB_P_JUMP, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ), HB_P_NOOP, ( BOOL ) 1 ); - hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 1 ); - } - else -#endif if( HB_LIM_INT24( lOffset ) ) { hb_compGenPCode4( HB_P_JUMPFAR, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ), ( BYTE ) ( ( lOffset >> 16 ) & 0xFF ), ( BOOL ) 1 ); @@ -2722,36 +2692,6 @@ ULONG hb_compGenJump( LONG lOffset ) ULONG hb_compGenJumpFalse( LONG lOffset ) { - /* - * optimizing jumps here by shorting them and setting HB_P_NOOPs - * only slow down the compilation process for three reasons: - * 1. When it's dummy jump to next instruction we need two passes - * in hb_compOptimizeJumps() to fully remove it - * 2. hb_compOptimizeJumps() also make jump shortcutting in each pass - * 3. When Jump Optimization is disabled (-kJ) then it cause slowness - * at runtime because we will have more HVM loops: first for the - * shorter jump and next for the HB_P_NOOP PCODE(s) - * [druzuz] - */ -#if 0 - /* Just a place holder, it might be a far jump...*/ - if( lOffset == 0 ) - { - hb_compGenPCode4( HB_P_JUMPFALSEFAR, 0, 0, 0, ( BOOL ) 1 ); - } - else if( HB_LIM_INT8( lOffset ) ) - { - hb_compGenPCode4( HB_P_JUMPFALSENEAR, HB_LOBYTE( lOffset ), HB_P_NOOP, HB_P_NOOP, ( BOOL ) 1 ); - hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 2 ); - hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 1 ); - } - else if( HB_LIM_INT16( lOffset ) ) - { - hb_compGenPCode4( HB_P_JUMPFALSE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ), HB_P_NOOP, ( BOOL ) 1 ); - hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 1 ); - } - else -#endif if( HB_LIM_INT24( lOffset ) ) { hb_compGenPCode4( HB_P_JUMPFALSEFAR, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ), ( BYTE ) ( ( lOffset >> 16 ) & 0xFF ), ( BOOL ) 1 ); @@ -2768,36 +2708,6 @@ ULONG hb_compGenJumpFalse( LONG lOffset ) ULONG hb_compGenJumpTrue( LONG lOffset ) { - /* - * optimizing jumps here by shorting them and setting HB_P_NOOPs - * only slow down the compilation process for three reasons: - * 1. When it's dummy jump to next instruction we need two passes - * in hb_compOptimizeJumps() to fully remove it - * 2. hb_compOptimizeJumps() also make jump shortcutting in each pass - * 3. When Jump Optimization is disabled (-kJ) then it cause slowness - * at runtime because we will have more HVM loops: first for the - * shorter jump and next for the HB_P_NOOP PCODE(s) - * [druzuz] - */ -#if 0 - /* Just a place holder, it might be a far jump...*/ - if( lOffset == 0 ) - { - hb_compGenPCode4( HB_P_JUMPTRUEFAR, 0, 0, 0, ( BOOL ) 1 ); - } - else if( HB_LIM_INT8( lOffset ) ) - { - hb_compGenPCode4( HB_P_JUMPTRUENEAR, HB_LOBYTE( lOffset ), HB_P_NOOP, HB_P_NOOP, ( BOOL ) 1 ); - hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 2 ); - hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 1 ); - } - else if( HB_LIM_INT16( lOffset ) ) - { - hb_compGenPCode4( HB_P_JUMPTRUE, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ), HB_P_NOOP, ( BOOL ) 1 ); - hb_compNOOPadd( hb_comp_functions.pLast, hb_comp_functions.pLast->lPCodePos - 1 ); - } - else -#endif if( HB_LIM_INT24( lOffset ) ) { hb_compGenPCode4( HB_P_JUMPTRUEFAR, HB_LOBYTE( lOffset ), HB_HIBYTE( lOffset ), ( BYTE ) ( ( lOffset >> 16 ) & 0xFF ), ( BOOL ) 1 ); @@ -2817,94 +2727,6 @@ void hb_compGenJumpThere( ULONG ulFrom, ULONG ulTo ) BYTE * pCode = hb_comp_functions.pLast->pCode; LONG lOffset = ulTo - ulFrom + 1; - /* - * optimizing jumps here by shorting them and setting HB_P_NOOPs - * only slow down the compilation process for three reasons: - * 1. When it's dummy jump to next instruction we need two passes - * in hb_compOptimizeJumps() to fully remove it - * 2. hb_compOptimizeJumps() also make jump shortcutting in each pass - * 3. When Jump Optimization is disabled (-kJ) then it cause slowness - * at runtime because we will have more HVM loops: first for the - * shorter jump and next for the HB_P_NOOP PCODE(s) - * [druzuz] - */ -#if 0 - if( HB_LIM_INT8( lOffset ) ) - { - switch( pCode[ ( ULONG ) ( ulFrom - 1 ) ] ) - { - case HB_P_JUMPFAR : - pCode[ ( ULONG ) ( ulFrom - 1 ) ] = HB_P_JUMPNEAR; - pCode[ ( ULONG ) ( ulFrom + 1 ) ] = HB_P_NOOP; - pCode[ ( ULONG ) ( ulFrom + 2 ) ] = HB_P_NOOP; - break; - - case HB_P_JUMPTRUEFAR : - pCode[ ( ULONG ) ( ulFrom - 1 ) ] = HB_P_JUMPTRUENEAR; - pCode[ ( ULONG ) ( ulFrom + 1 ) ] = HB_P_NOOP; - pCode[ ( ULONG ) ( ulFrom + 2 ) ] = HB_P_NOOP; - break; - - case HB_P_JUMPFALSEFAR : - pCode[ ( ULONG ) ( ulFrom - 1 ) ] = HB_P_JUMPFALSENEAR; - pCode[ ( ULONG ) ( ulFrom + 1 ) ] = HB_P_NOOP; - pCode[ ( ULONG ) ( ulFrom + 2 ) ] = HB_P_NOOP; - break; - - /* there is no shorter jump version for these PCODEs */ - case HB_P_SEQBEGIN : - case HB_P_SEQEND : - HB_PUT_LE_UINT24( &pCode[ ulFrom ], lOffset ); - return; - - default: - /* printf( "\rPCode: %i", pCode[ ( ULONG ) ulFrom - 1 ] ); */ - hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_JUMP_NOT_FOUND, NULL, NULL ); - break; - } - - pCode[ ( ULONG ) ulFrom ] = HB_LOBYTE( lOffset ); - - hb_compNOOPadd( hb_comp_functions.pLast, ulFrom + 1 ); - hb_compNOOPadd( hb_comp_functions.pLast, ulFrom + 2 ); - } - else if( HB_LIM_INT16( lOffset ) ) - { - switch( pCode[ ( ULONG ) ( ulFrom - 1 ) ] ) - { - case HB_P_JUMPFAR : - pCode[ ( ULONG ) ( ulFrom - 1 ) ] = HB_P_JUMP; - pCode[ ( ULONG ) ( ulFrom + 2 ) ] = HB_P_NOOP; - break; - - case HB_P_JUMPTRUEFAR : - pCode[ ( ULONG ) ( ulFrom - 1 ) ] = HB_P_JUMPTRUE; - pCode[ ( ULONG ) ( ulFrom + 2 ) ] = HB_P_NOOP; - break; - - case HB_P_JUMPFALSEFAR : - pCode[ ( ULONG ) ( ulFrom - 1 ) ] = HB_P_JUMPFALSE; - pCode[ ( ULONG ) ( ulFrom + 2 ) ] = HB_P_NOOP; - break; - - /* there is no shorter jump version for these PCODEs */ - case HB_P_SEQBEGIN : - case HB_P_SEQEND : - HB_PUT_LE_UINT24( &pCode[ ulFrom ], lOffset ); - return; - - default: - /* printf( "\rPCode: %i", pCode[ ( ULONG ) ulFrom - 1 ] ); */ - hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_JUMP_NOT_FOUND, NULL, NULL ); - break; - } - - HB_PUT_LE_UINT16( &pCode[ ulFrom ], lOffset ); - - hb_compNOOPadd( hb_comp_functions.pLast, ulFrom + 2 ); - } - else -#endif if( HB_LIM_INT24( lOffset ) ) { HB_PUT_LE_UINT24( &pCode[ ulFrom ], lOffset ); diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index 9f8783782d..6e7cd6d7bd 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -1616,19 +1616,11 @@ ForNext : FOR LValue ForAssign Expression /* 1 2 3 4 */ TO Expression StepExpr /* 6 7 8 */ { hb_compLoopStart(); - $$ = hb_comp_functions.pLast->lPCodePos; /* 9 */ - hb_compExprGenPush( $2 ); /* counter */ - hb_compExprGenPush( $7 ); /* end */ - if( $8 ) - hb_compExprGenPush( $8 ); /* step */ + $$ = hb_compGenJump( 0 ); /* 9 */ } Crlf /* 10 */ { - if( $8 ) - hb_compGenPCode1( HB_P_FORTEST ); - else - hb_compGenPCode1( HB_P_GREATER ); - $$ = hb_compGenJumpTrue( 0 ); /* 11 */ + $$ = hb_comp_functions.pLast->lPCodePos; /* 11 */ } ForStatements /* 12 */ { @@ -1661,8 +1653,19 @@ ForNext : FOR LValue ForAssign Expression /* 1 2 3 4 */ hb_compExprClear( hb_compExprGenStatement( hb_compExprNewPreInc( $2 ) ) ); } - hb_compGenJump( $9 - hb_comp_functions.pLast->lPCodePos ); - hb_compGenJumpHere( $11 ); + hb_compGenJumpHere( $9 ); + + hb_compExprGenPush( $2 ); /* counter */ + hb_compExprGenPush( $7 ); /* end */ + if( $8 ) + { + hb_compExprGenPush( $8 ); /* step */ + hb_compGenPCode1( HB_P_FORTEST ); + } + else + hb_compGenPCode1( HB_P_GREATER ); + + hb_compGenJumpFalse( $11 - hb_comp_functions.pLast->lPCodePos ); hb_compLoopEnd(); if( hb_compExprAsSymbol($2) ) {