Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Various compiler questions

Author: James Robertson

Date: 14:28:25 01/14/02

Go up one level in this thread


On January 14, 2002 at 13:31:39, Ed Schröder wrote:

>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)?
>
>James, welcome back.

Thanks. =) I hope to post here periodically as my school schedule allows.

>
>
>>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;
>}
>
>A good compiler will make use of the "indirect call", that is it will generate a
>table, store the memory address of the functions, and call the right routine
>from the generated table. The advantage, it takes 1 instruction.
>
>
>>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?
>
>See above.
>
>If you are using values that are in a reasonable range then create the table
>yourself. I recently posted an example of that for generating moves, you will
>have to search for that in the archive.
>
>Ed

Ok, this looks interesting. Assuming I create this table that contains locations
of other pieces of code (not other functions), then how would I be able to jump
to these other locations in the code based on some sort of array reference? I
don't think I'm familiar with the syntax. I'll see what I can do about searching
for stuff in the archive, but that might take more time than I can spare.

Thanks for you help. =)

James


>
>
>
>
>
>>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?
>>
>>4) What are the syntax differences between console code written for Linux versus
>>Unix (I don't have easy access to a Unix machine)?
>>
>>5) Just out of curiousity, when is VC7 being released?
>>
>>Ok, If anyone could help me with these I'd be grateful.
>>Thanks!
>>James



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.