Author: Robert Hyatt
Date: 10:09:17 09/02/02
Go up one level in this thread
On September 02, 2002 at 00:55:34, Pham Hong Nguyen wrote: >On September 01, 2002 at 23:33:26, Robert Hyatt wrote: > >>On September 01, 2002 at 20:46:55, Pham Hong Nguyen wrote: >> >>>The following article and discussion may be useful for you! >>> >>>http://www.codeguru.com/cpp_mfc/switch.html >> >> >>That is basically wrong. >> >>Compile a simple piece of code with gcc, using -O and you will see >>why. >> >>gcc creates a jump table of addresses for each case. It computes the >>entry to load and jumps to that. No compares and branches. Someone > >How can switch not compare when values are not continueing? >For example, >case -1; >case 3; >case 10; >case 234; > Easy... create a jump table with 238 entries, one for each of the values you gave, the rest being either jumps to the "default" case or jumps to the end of the switch if you don't do a default. The question becomes how large can the jump table be? The answer is, it can be as large as you are willing to bear. It costs memory. In the "old days" the table had to be pretty small, but today, you could easily have values like 0, 100000 if you wanted to optimize for speed rather than for memory. In chess, for example, the values are usually pretty continuous, such as -6, ..., -1, 0, 1, ... 6 for the 13 possible values a chessboard square might have... jump tables work just fine there... >>doesn't know how compilers do things. If you have really oddball case >>value, it might have to resort to that. But for the kinds of values >>we use in chess, no way...
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.