sagar474
Full Member level 5
- Joined
- Oct 18, 2009
- Messages
- 285
- Helped
- 5
- Reputation
- 10
- Reaction score
- 5
- Trophy points
- 1,318
- Location
- India,kakinada
- Activity points
- 3,122
if( c>=65 && c<=90 )
FUNCTION_IF_TRUE();
else if ( c>=97 && c<=122 )
FUNCTION_IF_TRUE();
else if ( c>=48 && c<=57 )
FUNCTION_IF_TRUE();
yes you are right branching instructions effects the pipelining of the processor but there is no way to completely avid the if statement.Actually, it is hard to tell if using if-else can save some clock cycles... If - else will be translated to multiple branch instructions and it creates more chance of misprediction and CPU may have to backtrack.. This is a typical case of performance loss in today's processors that employs speculative execution. Branch instructions are evil for computer architecture that disrupts the pipeline and in general, it's better to have fewer branch instructions.
Unless you know how gcc works, or there is a very obvious reason to believe a certain code can get a better performance, i don't think it's worth to play with coding style too much.
if((c>=65 && c<=90)||(c>=97 && c<=122)||(c>=48 && c<=57))
I'm following if statement in my code
I think it takes more execution. is there any alternative. to do this?
yanamaddinaveen said:I think switch statement is better to use it saves number of clock cycles and makes execution faster......what do you all say??
0x80487e8 cmp bx,0x40
0x80487ec jle 0x80487f4 <main+128>
0x80487ee cmp bx,0x7a
0x80487f2 jle 0x8048800 <main+140>
0x80487f4 cmp bx,0x2f
0x80487f8 jle 0x804881e <main+170>
0x80487fa cmp bx,0x39
0x80487fe jg 0x804881e <main+170>
0x8048800 movsx eax,si
0x8048803 add eax,DWORD PTR [esp+0x1c]
0x8048807 mov edx,ebx
0x8048809 mov BYTE PTR [eax],dl
0x804880b add esi,0x1
0x804880e mov eax,DWORD PTR [esp+0x18]
0x8048812 mov DWORD PTR [esp],eax
0x80487ec jle 0x8048801 <main+141>
0x80487ee cmp bx,0x7a
0x80487f2 jg 0x8048801 <main+141>
0x80487f4 movsx eax,si
0x80487f7 add eax,DWORD PTR [esp+0x1c]
0x80487fb mov edx,ebx
0x80487fd mov BYTE PTR [eax],dl
0x80487ff jmp 0x8048818 <main+164>
0x8048801 cmp bx,0x2f
0x8048805 jle 0x804882b <main+183>
0x8048807 cmp bx,0x39
0x804880b jg 0x804882b <main+183>
0x804880d movsx eax,si
0x8048810 add eax,DWORD PTR [esp+0x1c]
0x8048814 mov edx,ebx
0x8048816 mov BYTE PTR [eax],dl
0x8048818 add esi,0x1
what is "dumb" embedded compiler ?Because it's a "dumb" embedded compiler
A compiler that e.g. isn't able to detect repetitions in the code. As said, it may be a matter of low optimizations settings as well.what is "dumb" embedded compiler ?
yes i have removed some check to optimize. although the concept of question is not changed.What did you change to post #12, I'm under the impression, that it isn't the code I've seen previously. There's apparently something missing.
A compiler that e.g. isn't able to detect repetitions in the code. As said, it may be a matter of low optimizations settings as well.
You snipped the code and I can't see that.but what i have noticed is if c<=122 there is no need to compare if(c>=48 && c<=57) but in second case it is doing that.
are you certain ?there is same type of problem in case one.
I'm sorry but now you can see that.You snipped the code and I can't see that.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?