[MPlayer-dev-eng] Re: [PATCH] Development (Was: Clean up

Michael Niedermayer michaelni at gmx.at
Tue Feb 26 15:22:27 CET 2002


Hi

On Tuesday 26 February 2002 13:22, Daniel Egger wrote:
> Am Die, 2002-02-26 um 04.28 schrieb D Richard Felker III:
> > actually, from my experience, this is only done when the type you're
> > switching on is (maybe only unsigned) char and there are sufficiently
> > many cases to make fundtion pointers worth the extra overhead beyond
> > the 'dumb' implementation (which i assume would be O(log(n))
> > comparisons organized in a binary tree).
>
> Actually the dumb implementation is O(n). I've not seen a compiler which
> does partitioning on the switch-type.
well, indeed gcc is smarter then most of the ppl in this thread ;)
it uses a jump table which is O(1)

but try it yourself both source & compiled( not assembled) files attached

compiled with gcc -O4 switch.c -S -o switch.s
gcc version 2.95.4

Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: switch.s
Type: text/x-assembler
Size: 1453 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20020226/7810f096/attachment.bin>
-------------- next part --------------
volatile int v=10;

main()
{
v= switchy(v);
}

int switchy(int x)
{
	int y;
		switch(x)
		{
		case 1: y=5; break;
		case 2: y=1; break;
		case 3: y=2; break;
		case 4: y=3; break;
		case 5: y=4; break;
		case 6: y=5; break;
		case 7: y=9; break;
		case 8: y=8; break;
		case 9: y=7; break;
		case 10: y=6; break;
		case 11: y=5; break;
		case 12: y=4; break;
		case 13: y=3; break;
		case 14: y=1; break;
		case 15: y=11; break;
		case 16: y=111; break;
		case 17: y=1111; break;
		case 18: y=11111; break;
		}

	return y;
}


More information about the MPlayer-dev-eng mailing list