Author: Bo Persson
Date: 03:28:23 07/19/02
Go up one level in this thread
On July 19, 2002 at 00:48:21, Russell Reagan wrote: >On July 18, 2002 at 20:04:46, Robert Hyatt wrote: > >>You really have to test. And then test again in a few months after your >>code is more complex and "register jams" or "register spills" become a >>problem.. > >Could you explain what these things are? Register jams and spills. To have fast access to the data, the compiler tries to keep as much of it as possible in the processors registers. This works fine as long as it all fits there. If you add some operations (or reorder them somewhat) it might happen that there are not enough registers to store all the values needed at a particular point in the program, say a loop. The compiler then has to generate extra instructions to "spill" the overflow to memory, to free up some registers. When the "spilled" values are later needed, it will have to reload them again, possibly introducing another spill. This is nothing you want in you inner loops, of course. :-) BTW, the x86 architecture is well known for its low number of registers. >Also, to be >able to competently look at the ASM that is generated, how much do I need to >learn? Is it enough to look at it and think, "1 load from memory, 1 AND >operation, one test operation, totalling 3 operations, which is better than the >other approach which uses 4 operations."? Or do things get more complicated > than that? Yes, unfortunately it is a little more complicated. :-( Not all instructions execute in the same amount of time. It also differs between processor generations and manufacturers. Not fun at all! Also, a load from memory will might take anything from a few to a few *hundred* clock cycles, depending on if and where it is cached or if it is accessed from memory. >I think there are some things I'm not sure about. For example, does >dereferencing a pointer (pointer_to_something->field) "cost" anything? Where >could I learn these kinds of things? Am I better off just learning ASM >altogether? As usual: It depends! When accessing thru a pointer, the processor has to first load the pointer into a register, and then use the register (with a possible offset value) to access the data. This adds an additional load instruction at the start of a sequence. *However*, if you are accessing several fields of the structure, you might profit from the pointer anyway, because after the initial pointer load the following instructions don't need to carry the address and so can be shorter. Shorter instructions might execute faster and/or fit better in the cache. A lot of fun. :-) You can find some of the glory details at Intel's and AMD's sites: http://developer.intel.com http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739,00.html 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.