Author: Bo Persson
Date: 09:39:33 01/14/02
Go up one level in this thread
On January 14, 2002 at 12:11:52, James Robertson wrote:
>Here are several questions I've been wondering about:
>
>1) How does one insert inline assembler statements into your code such that it
>can be compiled by gcc (obviously __asm doesn't work)?
>
>2) How is switch() code generated? For instance, if the compiler encounters:
>switch (var) {
>case 0: do_stuff0(); break;
>case 1: do_stuff1(); break;
>case 2: do_stuff2(); break;
>}
>will more efficient code be generated than if I write:
>switch (var) {
>case 297: do_stuff287; break;
>case 0: do_stuff0; break;
>case 9000: do_stuff9000; break;
>}
>If so, what does the compiler do to take advantage of the fact that 0, 1, and 2
>are consecutive numbers?
For just 0, 1, and 2: probably not much. :-)
If there are many, consecutive values the compiler might build an address table
for the case labels, and then use something similar to
"goto table[var]", which may, or may not, be slightly faster.
Your second example will probably be implemented exactly as would:
if (var == 297)
...
else if (var == 0)
...
else if (var == 9000)
...
>3) How much overhead is added to a function call from a function pointer? Maybe
>none? How about if you index an array of function pointers?
Maybe none, maybe some... :-)
The standard answer is, of course: "It depends".
Is the function pointer stored somewhere? Is there a cost in retrieving it (a
parameter passed in a register, or is it stored in uncached memory) ?
A definite cost is that branch prediction logic will have a really hard time
predicting where the branch is going.
BTW, I have almost *never* found good use for a function pointer table. Care to
give me some hints? :-)
>4) What are the syntax differences between console code written for Linux versus
>Unix (I don't have easy access to a Unix machine)?
Wouldn't now that.
>5) Just out of curiousity, when is VC7 being released?
This is the $64000 question over at the Microsoft news groups right now!
It will be officially LAUNCHED (whatever that means!) during the first half of
february, http://msdn.microsoft.com/vstudio/launch/default.asp
Whether it will also be DELIVERED is still an open question, unfortunately...
:-(
>Ok, If anyone could help me with these I'd be grateful.
>Thanks!
>James
Bo Persson
bop2@telia.com
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.