www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/24/22:13:59

Date: Tue, 24 Feb 1998 16:48:31 -0800 (PST)
Message-Id: <199802250048.QAA28512@adit.ap.net>
Mime-Version: 1.0
To: mert0236 AT sable DOT ox DOT ac DOT uk (Thomas Womack), djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: pointer to function ??

At 12:39  2/24/1998 GMT, Thomas Womack wrote:
>Paul 'Ozymandias' Harman (ozzy AT kasterborus DOT demon DOT co DOT uk) wrote:
>: James E Fisher wrote in message
>: <01bd4107$bba0dc60$77111111 AT jfisher DOT team17 DOT com>...
>: >The first idea of a pointer to the code is the fastest way as there is only
>: >one call to the required function (after the address of the function has
>: >been fetched).  Using a SWITCH statement is slower as it can end up as a
>: >list of IF() statements by the compiler.
>
>VC++ tends to produce jump tables instead ... so the only overhead is
>an indirected jump. I can't remember if you can do JMP
>[4*EAX+base_of_table], but if not you only need two instructions. It's
>pipeline-unfriendly, but it shouldn't take longer than the AI routine
>itself, particularly if the AI is doing anything non-trivial.

I think GCC has several methods of implementing a `switch'. If I'm right, it
can do a test sequence (like many `if's), a straight jump table, or even a
hashed jump table. I believe it decides which one to use based on the number
of cases and their density.

Btw, the indirect JMP can take any register or memory reference, so JMP
[base+reg*4] is indeed legal.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019