Author: Ed Schröder
Date: 10:40:24 10/10/01
Go up one level in this thread
On October 10, 2001 at 09:27:13, Ulrich Tuerke wrote: >On October 10, 2001 at 08:38:43, Travers Waker wrote: > >>Hi. >> >>I recently read that using word-sized variables for a particular machine (e.g. a >>32-bit int on an Intel PC CPU) yields faster code than using variables that are >>not the size of a word. >> >>For example, I understood the article to be saying that if you needed an index, >>i, to access an array, A[256], then it would yield faster code to define: >> >>int i; >> >>instead of: >> >>unsigned char i; >> >>even though the unsigend char is big enough to be able to index all the elements >>of the array. I find this strange, especially since it seems to me that you >>waste space in the memory caches when the most sinificant 3 bytes of the 32-bit >>int are always going to be zero's. >> >>Can someone explain to me why using word-sized variables should be faster? > >I think that the article is right. AFAIK, when indexing, the machines usually >use words. Thus, an index defined as a byte has to be "zero-extended" to >word-size. This will require an additional machine instruction. > >However, I doubt very much that it is worthwhile worrying about these >microscopic optimization effects. Wrong. Using 16 bits registers (words) is very slow, always use 32 bit registers (int) where ever you can. Large tables using char is okay as long as the index is an int. Ed >Uli >> >>Thanks >> >>Travers
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.