Author: Gerd Isenberg
Date: 09:50:32 07/17/03
Go up one level in this thread
On July 17, 2003 at 07:43:19, Uri Blass wrote:
>On July 17, 2003 at 06:43:30, Gerd Isenberg wrote:
>
>>On July 17, 2003 at 06:28:44, Uri Blass wrote:
>>
>>>On July 17, 2003 at 06:14:04, Richard Pijl wrote:
>>>
>>>>On July 17, 2003 at 05:58:39, Gerd Isenberg wrote:
>>>>
>>>>>On July 17, 2003 at 05:06:16, Uri Blass wrote:
>>>>>
>>>>>>Note that the name of the arrays that I have is different but I replaced the
>>>>>>names to make it easy to understand the problem.
>>>>>>
>>>>>>I have an array A[64][8]
>>>>>>
>>>>>>I want to replace it by 8 arrays A0[64],A1[64],...A7[64] when A[i][j]=Aj[i]
>>>>>
>>>>>Hi Uri,
>>>>>
>>>>>I would suggest A[8][64] for your purpose.
>>>>>
>>>>>Then you still may index the arrays with A[j][sq] and you get your suggested
>>>>>single 64 element arrays: A0[sq], A1[sq] with A[0][sq], A[1][sq] ...
>>>>>
>>>>>Gerd
>>>>
>>>>Of course! Let the compiler do the optimizing. I guess most compilers will
>>>>recognize this?
>>>>Richard.
>>>
>>>Your suggestion seems to be better.
>>>
>>>The point is that I have significant names instead of A0,A1,.... and I do not
>>>want to lose the significant names.
>>>
>>>I only wrote here A0, A1 to explain the point because otherwise I cannot use a
>>>simple formula based on the name of the array.
>>>
>>>I already finished the replace of the array and I now only need to add your
>>>definitions and save calculations that are done twice for both arrays.
>>>
>>>The arrays practically are not the same but every time that I call A[i][j] it is
>>>the same as Ai[j], so it is a waste of time to calculate A[i][j]
>>
>>Uri, if "i" is a constant, there is no waste of time!
>>A1[j] or A[1][j] produce the same assembler output.
>
>I understand it but this was not the point of this post(I was wrong to think
>that A[0][j] is faster than A0[j] from the computer point of view in the
>original post but not in this post and there were reasons to add the new arrays
>that are not speed).
>
>I will try to explain it more clearly.
>
>At this point I only checked for no bugs after replacing A[64][8] by A[8][64]
>
>Ai[j] is a different array than A[i][j] and has a different place in the memory
>of the computer.
>
>Ai[j] simply gives me more information than A[i][j] so I do not need the old
>A[i][j]
>
>I have
>1)A[i][j]=Ai[j] if condition X happens.
>2)A[i][j] is used only if condition X happens.
>3)A[i][j]<>Ai[j] is possible if X does not happen.
>
>In the past I used only A[i][j] only when X happened
>I decide to build Ai[j] and now I use it also when x does not happen but A[i][j]
>is still used only when X happens.
>
>It means that I can replace A[i][j] by Ai[j] and save time of calculation of
>A[i][j].
>
>The problem was how to calculate Ai[j] when I have only i and j and i is not a
>constant.
>In the last version I still use simply A[i][j]
>I did not like to use switch and I also do not like to use A[i][j] instead of
>Ai[j] because the names of Ai are significant names(I have 8 names that are
>different english words when using 8 different words in the array A[8][64] is
>not practical).
>
>The solution that Richard prposed seems to be good because I can keep the
>original 8*64 array only in the definitions and use the significant names.
>
>I can also save time relative to the situation today because I do not need to
>calculate the old array.
>
>I did not post the full inforamtion in the original post because I thought that
>the fact that A[i][j] gives more information than Ai[j] is irrelvant because
>there was a different reason of speed to support Ai[j].
>
>More information may also support speed and not only knowledge but I thought
>that if I give too complex post then I may confuse people.
>
>Uri
sorry Uri, a bit short in time (on Work) ...
I'm not sure i understand your problems...
You have the old int array with swapped indicies [8][64] now.
You need a second one with some conditional stuff.
You are not sure whether you should use a second two dimensional array or eight
single 64 elements arrays, because of more readable identifier.
I can only suggest a second two dimensional array.
For better reading you may use an own enum (or defines) and instead of using
A[0] you may write A[NORTH] or similar.
enum // optional Type qualifier
{
NORTH = 0,
NORTH_EAST,
EAST,
SOUTH_EAST,
SOUTH,
SOUTH_WEST,
WEST,
NORTH_WEST,
N_DIRS // = 8
};
int Aold[N_DIRS][64]; // unspecified Aold is an int**, Aold[i] is int*
int Acond[N_DIRS][64];
you do conditionally something like this
for (j=NORTH; j < N_DIRS; j++)
for (sq=0; sq < 64; sq++)
if (condition)
Acond[j][sq] = functionOf(Aold[j][sq]);
else
Acons[j][sq] = Aold[j][sq]; // not sure about the else
Unspecified array identifier as pointer must be "right" values, but not "left"
values of a assignment (you can't change the address of an array).
But you may define a pointer array like this:
int* Aptr[8];
then you may assign pointers on 64 int arrays like this:
Aptr[j] = (someCondition) ? Acond[j] : Aold[j];
and you may pass Aptr[j] as RValue like Aold[j].
What about references and typedefs:
typedef int intArr[64];
typedef intArr int64Arr[8]; // typedefs make it much easier here
void arrtest()
{
int i,j;
int64Arr a; // same as intArr a[8] or int a[8][64]
for (j=0; j < 8; j++)
for (i=0; i < 64; i++)
a[j][i] = j*i;
int64Arr &b = a; // only a pointer assignment
for (j=0; j < 8; j++)
for (i=0; i < 64; i++)
if ( b[j][i] != j*i)
__asm int 3;
}
Hope this helps in some way...
Gerd
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.