U64 bmagic[64] = {
0x20020208448c0280,
0x00014802544002c0,
0x011c4118104402e0,
0x0405040009000300,
0x4014402210000320,
0x000010c030000340,
0x0000480040b00360,
0x004014080a200380,
0x04303020404203c0,
0x05003414004403e0,
0x4808140100100400,
0x1000480204680420,
0x6124210042000440,
0x0001480803080460,
0x0052000400c40480,
0x00000100090204a0,
0x000500a0020a04c0,
0x00100000401104e0,
0x0210210900400500,
0x0008084914000580,
0x1810204402200600,
0x042a080808010680,
0x1040092004720700,
0x0000400044280720,
0x3020008000500740,
0x0000100008010760,
0x0000410208820780,
0x0b10040003050800,
0x00c4082104002000,
0x0004000809002200,
0x0004052418202280,
0x44020140008022a0,
0x02001005000422c0,
0x08320010404122e0,
0x0002008040402300,
0x0208202020480080,
0x0428060400113010,
0x0010008020003210,
0x0102020004803290,
0x504021014a4032b0,
0x00831108008032d0,
0x00000904088032f0,
0x0800240022003310,
0x0840604201003390,
0x0004080101043410,
0x0482020804083490,
0x0a8201a026203510,
0x200101200a203530,
0x5002004406013550,
0x0002008425003570,
0x41000314000c3590,
0x04010001050035b0,
0x01000000409035d0,
0x20402810004135f0,
0x1d20008242243610,
0x10002a0014003630,
0x2014201030003650,
0x0010022038203690,
0x00922200204836b0,
0x23000000004036d0,
0x01900004011436f0,
0x0000000200943710,
0x0000053000823730,
0x30040511010a3750
};
...and attacks function like this:
inline U64 battacks(int sq,U64 occ)
{
register U64 m=bmagic[sq];
return battacksdata[m&0xffff+((m*occ)>>55)];
}
the idea is without offset and shift array
?
magic number comprising offset
Moderators: hgm, Rebel, chrisw
-
- Posts: 266
- Joined: Fri Jul 10, 2015 9:23 pm
- Location: Russia
-
- Posts: 2250
- Joined: Wed Mar 08, 2006 8:47 pm
- Location: Hattingen, Germany
Re: magic number comprising offset
Nice! One extra register, parallel executed "and" (with mul) instead of L1 access. I guess it depends on the surrounding instructions and register pressure whether your proposal is faster or slower.
-
- Posts: 855
- Joined: Sun May 23, 2010 1:32 pm
Re: magic number comprising offset
this is all the code for the bishop magic? I'll give it a try
-
- Posts: 266
- Joined: Fri Jul 10, 2015 9:23 pm
- Location: Russia
Re: magic number comprising offset
I know that this is not the most significant optimization. But a slightly something better than slightly nothing ))Gerd Isenberg wrote:Nice! One extra register, parallel executed "and" (with mul) instead of L1 access. I guess it depends on the surrounding instructions and register pressure whether your proposal is faster or slower.
Last edited by Kotlov on Sat Feb 10, 2018 11:04 am, edited 1 time in total.
-
- Posts: 266
- Joined: Fri Jul 10, 2015 9:23 pm
- Location: Russia
Re: magic number comprising offset
Yes, is real magic numbers. I wrote a special code to generate them, it is not difficult. But need write special init code to formed attackdata based on this magic numbers.elcabesa wrote:this is all the code for the bishop magic? I'll give it a try
-
- Posts: 12541
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: magic number comprising offset
If nothing else, it is pretty to look at it!
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.