Author: Gerd Isenberg
Date: 06:14:38 06/02/04
Go up one level in this thread
One more note ...
The same optimization occurs with an int-array, if one is aware of the q-value
range, eg. if q values are in the range from 0..15 it is only necessary to shift
by four. Considering OOE and register renaming, could one beat that with
assembly?
I guess your intention is to get an 8-bit index of all possible surrounding king
squares, considering board symmetry (back,front,luv,lee) and to get information
on escape squares, eg. whether there is only one square, or two squares on one
coomon ray to escape - nice!
May be an alternative solution to frickle an inner six square occupied state
from a ray to index precalculated attack tables without rotated bitboards,
specially if your piececodes are already negative, but empty is null ;-)
Cheers,
Gerd
int pack2bits(int q[8])
{
int bitfield;
bitfield = ((-q[7]>>4) & 128)
| ((-q[6]>>4) & 64)
| ((-q[5]>>4) & 32)
| ((-q[4]>>4) & 16)
| ((-q[3]>>4) & 8)
| ((-q[2]>>4) & 4)
| ((-q[1]>>4) & 2)
| ((-q[0]>>4) & 1);
return bitfield;
}
PUBLIC ?pack2bits@@YAHQAH@Z ; pack2bits
; Function compile flags: /Ogty
; COMDAT ?pack2bits@@YAHQAH@Z
_TEXT SEGMENT
_q$ = 8
?pack2bits@@YAHQAH@Z PROC NEAR ; pack2bits, COMDAT
00000 8b 4c 24 04 mov ecx, DWORD PTR _q$[esp-4]
00004 8b 41 1c mov eax, DWORD PTR [ecx+28]
00007 8b 51 18 mov edx, DWORD PTR [ecx+24]
0000a f7 d8 neg eax
0000c f7 da neg edx
0000e 25 00 08 00 00 and eax, 2048 ; 00000800H
00013 81 e2 00 04 00 00 and edx, 1024 ; 00000400H
00019 0b c2 or eax, edx
0001b 8b 51 14 mov edx, DWORD PTR [ecx+20]
0001e f7 da neg edx
00020 81 e2 00 02 00 00 and edx, 512 ; 00000200H
00026 0b c2 or eax, edx
00028 8b 51 10 mov edx, DWORD PTR [ecx+16]
0002b f7 da neg edx
0002d 81 e2 00 01 00 00 and edx, 256 ; 00000100H
00033 0b c2 or eax, edx
00035 8b 51 0c mov edx, DWORD PTR [ecx+12]
00038 f7 da neg edx
0003a 81 e2 80 00 00 00 and edx, 128 ; 00000080H
00040 0b c2 or eax, edx
00042 8b 51 08 mov edx, DWORD PTR [ecx+8]
00045 f7 da neg edx
00047 83 e2 40 and edx, 64 ; 00000040H
0004a 0b c2 or eax, edx
0004c 8b 51 04 mov edx, DWORD PTR [ecx+4]
0004f 8b 09 mov ecx, DWORD PTR [ecx]
00051 f7 da neg edx
00053 83 e2 20 and edx, 32 ; 00000020H
00056 f7 d9 neg ecx
00058 0b c2 or eax, edx
0005a 83 e1 10 and ecx, 16 ; 00000010H
0005d 0b c1 or eax, ecx
0005f c1 f8 04 sar eax, 4
00062 c3 ret 0
?pack2bits@@YAHQAH@Z ENDP ; pack2bits
_TEXT ENDS
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.