| ??? 07/11/08 08:58 Modified: 07/11/08 09:06 Read: times |
#156600 - Keil C 51 Optimizations Responding to: ???'s previous message |
Thank you.
We have evaluated the C 51 for optimizations and have found it does not perform many common optimizations. The test cases for two such optimizations is placed below. My questions: 1. As a user how significant would it be to have these optimizations? 2. What are the really important optimizations for developers working with the 8051? RM PS: I think I should have posted this as the root of a new chain. Could one of the moderators please do this? ******************************************* 1. Test code for dead variable elimination.
signed char scGlobalVariable1, scGlobalVariable2, scGlobalVariable3, scGlobalVariable4 ;
extern signed char scGlobalVariableResult ;
void CreateVariableUsage ( void ) ;
void main ( void )
{
if ( 0 != scGlobalVariable1 )
{
scGlobalVariable1 = scGlobalVariable2 + scGlobalVariable3 ; // Definition - 1
}
/*
Since there is no usage for the signed char global variable
'scGlobalVariable1' between its first and second definition,
the compiler can optimize 'Definition - 1' as part of
Dead variable elimination.
*/
scGlobalVariable1 = scGlobalVariable3 + scGlobalVariable4 ; // Definition - 2
CreateVariableUsage () ;
}
/*
Some optimizing compiler will eliminate the assignment code of a
variable when the variable has no further usage after its definition.
Therefore, to perform complete optimization evaluation, usage of a
variable has been created in this function.
*/
void CreateVariableUsage ( void )
{
scGlobalVariableResult = scGlobalVariable1 + scGlobalVariable2 + scGlobalVariable3 + scGlobalVariable4 ;
}
2. Test Code For Constant Propagation.
signed char scGlobalVariable1 = 15 ;
signed char scGlobalVariable2, scGlobalVariable3, scGlobalVariable4 ;
signed char scGlobalVariable5, scGlobalVariable6, scGlobalVariable7 ;
extern signed char scGlobalVariable8, scGlobalVariableResult ;
void CreateVariableUsage ( void ) ;
void main ( void )
{
scGlobalVariable2 = 10 ;
scGlobalVariable3 = 5 ;
if ( 0 != scGlobalVariable8 )
{
/*
Constant propagation should be performed for the below
usage of 'scGlobalVariable1' and 'scGlobalVariable3'
Constant value 15 is to be propagated to 'scGlobalVariable1'
and constant value 5 is to be propagated to 'scGlobalVariable3'.
Result of 'scGlobalVariable1 * scGlobalVariable3' (15 * 5)
should be folded to value 75 which is to be stored in
'scGlobalVariable4'.
*/
scGlobalVariable4 = scGlobalVariable1 * scGlobalVariable3 ;
/*
Constant propagation should be performed for the below
usage of 'scGlobalVariable1'
Constant value 15 is to be propagated to 'scGlobalVariable1'
which is to be stored in 'scGlobalVariable5'.
*/
scGlobalVariable5 = scGlobalVariable1 ;
}
else
{
/*
Constant propagation should be performed for the below
usage of 'scGlobalVariable2' and 'scGlobalVariable3'
Constant value 10 is to be propagated to 'scGlobalVariable2'
and constant value 5 is to be propagated to 'scGlobalVariable3'.
Result of 'scGlobalVariable2 + scGlobalVariable3' (10 + 5)
should be folded to value 15 which is to be stored in
'scGlobalVariable6'.
*/
scGlobalVariable6 = scGlobalVariable2 + scGlobalVariable3 ;
}
/*
Constant value 15 is to be propagated to 'scGlobalVariable1'
and constant value 10 is to be propagated to 'scGlobalVariable2'.
Result of 'scGlobalVariable1 - scGlobalVariable2' (15 - 10)
should be folded to value 5 which is to be stored in
'scGlobalVariable7'.
*/
scGlobalVariable7 = scGlobalVariable1 - scGlobalVariable2 ;
CreateVariableUsage () ;
}
/*
Some optimizing compiler will eliminate the assignment code of a
variable when the variable has no further usage after its definition.
Therefore, to perform complete optimization evaluation, usage of a
variable has been created in this function.
*/
void CreateVariableUsage ( void )
{
scGlobalVariableResult = scGlobalVariable2 + scGlobalVariable4 + scGlobalVariable5 + scGlobalVariable6 + scGlobalVariable7 ;
}
|
| Topic | Author | Date |
| Data Array getting corrupted after init | 01/01/70 00:00 | |
| OnePossibleIdea.... | 01/01/70 00:00 | |
| I did not do anything with the stack | 01/01/70 00:00 | |
| As Michael said.... | 01/01/70 00:00 | |
| How do you test and debug code? | 01/01/70 00:00 | |
| Keil is the only thing in place | 01/01/70 00:00 | |
| 'crap'?? | 01/01/70 00:00 | |
| Is this the book you refer? | 01/01/70 00:00 | |
| nope | 01/01/70 00:00 | |
| Erik | 01/01/70 00:00 | |
| So where is the code | 01/01/70 00:00 | |
| do NOT "put them" | 01/01/70 00:00 | |
| Focus | 01/01/70 00:00 | |
| Simulator | 01/01/70 00:00 | |
| So this is on a simulator? | 01/01/70 00:00 | |
| Post your duff code | 01/01/70 00:00 | |
| Finding Cause of Corruption | 01/01/70 00:00 | |
| Get the C right, then look at the target CPU | 01/01/70 00:00 | |
| Optimizing Compilers | 01/01/70 00:00 | |
| In my experience..... | 01/01/70 00:00 | |
| Keil C 51 Optimizations | 01/01/70 00:00 | |
| Use IAR then | 01/01/70 00:00 | |
| different approaches | 01/01/70 00:00 | |
| sometimes, depends | 01/01/70 00:00 | |
Thanks | 01/01/70 00:00 |



