I was asking you for some examples ..as i dont have any knowledge
regarding this assembly code and how to study it .
there was no intention of mine to challenge you or disregard you .
On 11/22/10, Gene wrote:
> I'm not sure what you mean by support.
>
> If you mean examples, gcc uses several of
I'm not sure what you mean by support.
If you mean examples, gcc uses several of the techniques I mentioned.
Write some switch statements with different distributions of cases.
Compile with -S, and inspect the assembly code. If you don't now how
to do that, take the time to learn.
If you mean ju
@dipankar
Can u tell us , sumthng more in support of ur ans...??
On Mon, Nov 22, 2010 at 10:40 AM, DIPANKAR DUTTA
wrote:
> both are same .. because any good optimizing compiler generate same assembly
> code of them...
>
> On Mon, Nov 22, 2010 at 9:38 AM, Gene wrote:
>>
>> A good compiler w
both are same .. because any good optimizing compiler generate same assembly
code of them...
On Mon, Nov 22, 2010 at 9:38 AM, Gene wrote:
> A good compiler will never generate a switch that is slower than an
> if...else chain. They will analyze the switch cases and pick one of
> several options
A good compiler will never generate a switch that is slower than an
if...else chain. They will analyze the switch cases and pick one of
several options for code generation. These may include cascaded
conditional jumps (like if...else code), simple jump tables, segmented
jump tables (cascaded jump
@Mohit:
No, it's just the hierarchical occurent of conditions that makes the
switch faster. I really doubt that a compiler build a binary search
tree for switches. Also, it a binary tree works for switches why it
can't optimize the if-else-condition? Did you make some testing?
On Nov 21, 3:28 pm
its depend on compiler how it optimize it . he can make binary search tree
for this comparison
or perform cascading comparison as in if else case .. so worst case
complexity will be as of
if- else .
but for this case
switch(i)
{
case 4: //some operation
case 5:// some operation
case 6 : //
som
As he told you it depends on the data runs to the condition. If for
exampe statistically there is more of 1's then 0 then the switch loop
is faster, because:
1.) case is isolated
2.) You can reorder the case-statement according to the occurrent of
the conditions
On Nov 21, 2:59 pm, shiva wrot
how it going to make difference in following case
--
i=0;
switch(i)
{
case 1: //some operation
case 0:// some operation
}
--
i=0;
if(i==1)
{
//some operation;
}
else if (i==0)
{
//Some operation
}
--