void AddLblRef( ins_entry *instr ) /***********************************/ { label_handle lbl; optbegin lbl = _Label( instr ); if( lbl->ins != NULL ) { lbl = _Label( lbl->ins ); _Label( instr ) = lbl; } _LblRef( instr ) = lbl->refs; lbl->refs = instr; optend }
extern void CloneCode( label_handle lbl ) /***************************************** consider: JMP L1 .... L1: POP AX RET we want to clone the code at L1 at the point of the jump, since it will be faster (and smaller since POP AX/RET is only 2 bytes while the JMP might be 3/5). */ { ins_entry *next; ins_entry *lbl_ins; ins_entry *hoist; ins_entry *jmp; unsigned size; unsigned max_size; lbl_ins = lbl->ins; if( lbl_ins == NULL ) return; size = 0; hoist = NextIns( lbl_ins ); for( next = hoist; ; next = NextIns( next ) ) { if( next == NULL ) return; if( _Class( next ) == OC_CODE && CodeHasAbsPatch( &next->oc.oc_entry ) ) return; if( _Class( next ) != OC_LABEL ) { size += _ObjLen( next ); if( size > MAX_CLONE_SIZE ) return; if( _TransferClass( _Class( next ) ) ) { break; } } } if( _Class( next ) == OC_JMP && _Label( next ) == lbl ) return; for( jmp = lbl->refs; jmp != NULL; jmp = _LblRef( jmp ) ) { if( next == jmp ) continue; if( !_TransferClass( _Class( jmp ) ) ) continue; max_size = _ObjLen( jmp ); if( size > max_size && FindShort( jmp, NULL ) ) continue; if( OptForSize < 50 ) { max_size *= (100-OptForSize) / 25; } if( size > max_size ) continue; DoCloneCode( jmp, hoist ); DelInstr( jmp ); } }
static void TransformJumps( ins_entry *ins, ins_entry *first ) /****************************************************************/ { ins_entry *add; ins_entry *next; ins_entry *lbl; oc_class cl; optbegin if( _Class( ins ) == OC_RET ) optreturnvoid; lbl = _Label( ins )->ins; if( lbl == NULL ) optreturnvoid; add = lbl; for( ;; ) { if( add == NULL ) optreturnvoid; cl = _Class( add ); if( _TransferClass( cl ) ) break; if( cl == OC_LABEL ) { if( _Attr( add ) & ATTR_SHORT ) optreturnvoid; _ClrStatus( _Label( add ), SHORTREACH ); } add = NextIns( add ); } if( add == first || add == ins ) optreturnvoid; if( FindShort( first, lbl ) ) optreturnvoid; for( ;; ) { next = PrevIns( add ); DeleteQueue( add ); InsertQueue( add, first ); if( add == lbl ) break; add = next; } DeleteQueue( first ); InsertQueue( first, next ); Untangle( NextIns( first ) ); optend }
void MainTask(void) { GUI_Init(); _Label(); while(1) { _DemoRandomGraph(); _DemoSineWave(); _DemoOrData(); } }
void GUIDEMO_Graph(void) { _YSize = (LCD_GetYSize() - 100); GUIDEMO_ShowIntro("Drawing a graph", "\nOptimized drawing routine" "\nfor drawing graph data"); GUI_Clear(); _Label(); _DemoRandomGraph(); GUIDEMO_NotifyStartNext(); _DemoSineWave(); }
static void _ShowJapaneseSample(void) { int i; _Label("Japanese text\nmixed with\nASCIItext"); GUI_SetFont(&_FontSJIS16); for (i=0;i<sizeof(_apSJIS)/sizeof(_apSJIS[0]);i++) { GUI_DispStringHCenterAt(_apSJIS[i], LCD_GetXSize() / 2, _GetYPos() + 20); GUI_DispNextLine(); } GUIDEMO_Wait(); GUIDEMO_NotifyStartNext(); }
void DelLblRef( ins_entry *instr ) /***********************************/ { label_handle old; optbegin old = _Label( instr ); DelRef( &old->refs, instr ); TryScrapLabel( old ); optend }
static void _ShowFonts(const char *s, const char *pMessage, const GUI_FONT **pPropFonts) { int i; _Label(s); GUI_GotoXY(0, _GetYPos()); for (i=0;pPropFonts[i];i++) { GUI_SetFont(pPropFonts[i]); GUI_DispString(pMessage); GUI_DispNextLine(); } GUIDEMO_Wait(); GUIDEMO_NotifyStartNext(); }
extern bool FindShort( ins_entry *ins, ins_entry *end ) /*********************************************************/ { for( ; ins != NULL && ins != end; ins = NextIns( ins ) ) { if( _Class( ins ) == OC_LABEL ) { if( _Attr( ins ) & ATTR_SHORT ) return( true ); _ClrStatus( _Label( ins ), SHORTREACH ); } } return( false ); }
void GUIDEMO_Graph(void) { GUIDEMO_ShowIntro("Drawing a graph", "\nOptimized drawing routine for" "\ndrawing graph data"); GUI_Clear(); _Label(); _DemoRandomGraph(); GUIDEMO_NotifyStartNext(); _DemoSineWave(); GUIDEMO_NotifyStartNext(); _DemoOrData(); }
void DelLblDef( ins_entry *instr ) /***********************************/ { label_handle lbl; optbegin lbl = _Label( instr ); if( lbl == NULL ) optreturnvoid; if( lbl->refs != NULL ) optreturnvoid; if( !_TstStatus( lbl, DYINGLABEL ) ) optreturnvoid; if( _TstStatus( lbl, REDIRECTION ) ) optreturnvoid; ScrapCodeLabel( lbl ); optend }
void AddLblDef( ins_entry *instr ) /***********************************/ { label_handle lbl; optbegin _LblRef( instr ) = NULL; lbl = _Label( instr ); for(;;) { _SetStatus( lbl, CODELABEL ); lbl->ins = instr; lbl = lbl->alias; if( lbl == NULL ) break; } optend }
extern void CallRet( ins_entry *instr ) /*****************************************/ { ins_entry *lbl; optbegin if( _Attr( instr ) & ATTR_POP ) optreturnvoid; lbl = _Label( instr )->ins; if( lbl == NULL ) optreturnvoid; if( NextClass( lbl ) != OC_RET ) optreturnvoid; _Savings( OPT_CALLTORET, _ObjLen( instr ) ); DelInstr( instr ); optend }
void GUIDEMO_Graph(void) { #if GUIDEMO_LARGE _YSize = (LCD_YSIZE - 100); #else _YSize = (LCD_YSIZE - 30); #endif GUIDEMO_ShowIntro("Drawing a graph", "\nOptimized drawing routine" "\nfor drawing graph data"); GUI_Clear(); _Label(); _DemoRandomGraph(); GUIDEMO_NotifyStartNext(); _DemoSineWave(); GUIDEMO_NotifyStartNext(); _DemoOrData(); }
extern void CheckStraightenCode( ins_entry *lbl_ins ) /********************************************************/ { label_handle lbl; ins_entry *jmp; optbegin if( lbl_ins != NULL ) { lbl = _Label( lbl_ins ); for( jmp = lbl->refs; jmp != NULL; jmp = _LblRef( jmp ) ) { if( !_TransferClass( _Class( jmp ) ) ) continue; if( StraightenCode( jmp ) ) { break; } } } optend }
extern void JmpRet( ins_entry *instr ) /****************************************/ { ins_entry *ret; optbegin if( InsDelete ) optreturnvoid; ret = _Label( instr )->ins; if( ret == NULL ) optreturnvoid; ret = NextIns( ret ); if( ret == NULL ) optreturnvoid; if( _Class( ret ) != OC_RET ) optreturnvoid; JmpToRet( instr, ret ); optend }
static void _ShowCharacters(const char*s, const GUI_FONT* pFont, int IncX) { int i; int ix=0, y; int FontSizeY; GUI_SetFont(pFont); FontSizeY = GUI_GetFontSizeY(); _Label(s); GUI_SetFont(pFont); y = _GetYPos(); for (i = 0; i < 20000; i++) { if (GUI_IsInFont(NULL, (U16)i)) { GUI_GotoXY(ix * IncX, y); if (ix++ > 20) { ix = 0; y += FontSizeY; } GUI_DispChar((U16)i); } } GUIDEMO_Delay(2000); GUIDEMO_NotifyStartNext(); }
old = _Label( instr ); DelRef( &old->refs, instr ); TryScrapLabel( old ); optend } void ChgLblRef( ins_entry *instr, label_handle new ) /*****************************************************/ { ins_entry **owner; ins_entry *curr; label_handle old; optbegin old = _Label( instr ); if( old != new ) { owner = &old->refs; for(;;) { curr = *owner; if( curr == instr ) break; owner = (ins_entry **)&_LblRef( curr ); } *owner = _LblRef( curr ); _LblRef( curr ) = new->refs; new->refs = curr; _Label( curr ) = new; TryScrapLabel( old ); } optend }
extern bool StraightenCode( ins_entry *jump ) /***********************************************/ { ins_entry *next; ins_entry *insert; ins_entry *hoist; ins_entry *end_hoist; oc_class cl; obj_length align; optbegin hoist = _Label( jump )->ins; if( hoist == NULL ) optreturn( false ); if( hoist == LastIns ) optreturn( false ); cl = PrevClass( hoist ); if( !_TransferClass( cl ) ) optreturn( false ); end_hoist = NULL; for( next = hoist; ; next = NextIns( next ) ) { if( next == jump ) { // pushing code down to jump if( end_hoist == NULL ) optreturn( false ); if( FindShort( hoist, end_hoist ) ) optreturn( false ); break; } if( next == NULL ) { // hauling code up to jump if( FindShort( jump, hoist ) ) optreturn( false ); break; } cl = _Class( next ); if( end_hoist == NULL && _TransferClass( cl ) ) { end_hoist = next; } } align = _ObjLen( hoist ); insert = jump; for( ;; ) { if( hoist == NULL ) { ChgLblRef( jump, AddNewLabel( LastIns, align ) ); next = LastIns; break; } next = NextIns( hoist ); DeleteQueue( hoist ); InsertQueue( hoist, insert ); if( hoist == jump ) optreturn( false ); insert = hoist; cl = _Class( hoist ); if( _TransferClass( cl ) ) { IsolatedCode( insert ); break; } hoist = next; } InsDelete = true; Untangle( next ); if( _Class( jump ) != OC_DEAD ) { Untangle( _Label( jump )->ins ); } optreturn( true ); }