| View previous topic :: View next topic |
| Author |
Message |
Gerd Isenberg
Joined: 08 Mar 2006 Posts: 1785 Location: Hattingen, Germany
|
Post subject: Re: Resource for bit twiddlers Posted: Mon May 28, 2007 3:16 pm |
|
|
| Gerd Isenberg wrote: |
| Code: |
u64 eastAttacks(u64 rooks, u64 empty)
{
const u64 H = 0x8080808080808080;
u64 occupied = rooks | ~empty;
u64 occNoRook = rooks ^ occupied;
u64 difference = ((occNoRook | H) - (rooks & ~H))
^ (~occupied & H);
return occupied ^ difference;
}
|
Gerd |
Oups, since
A ^ (~A & B) == A | B
the code becomes a bit cheaper:
| Code: |
u64 eastAttacks(u64 rooks, u64 empty)
{
const u64 H = 0x8080808080808080;
u64 occInclRook = rooks | ~empty;
u64 occExclRook = rooks ^ occInclRook;
u64 attacks = ((occExclRook | H) - (rooks & ~H))
^ (occInclRook | H);
return attacks;
}
|
|
|
| Back to top |
|
 |
|
| Subject |
Author |
Date/Time |
Resource for bit twiddlers |
J. Wesley Cleveland |
Fri May 04, 2007 1:55 am |
Re: Resource for bit twiddlers |
Gerd Isenberg |
Mon May 28, 2007 12:40 pm |
Re: Resource for bit twiddlers |
Gerd Isenberg |
Mon May 28, 2007 3:16 pm |
Re: Resource for bit twiddlers |
Gerd Isenberg |
Mon May 28, 2007 4:35 pm |
Re: Resource for bit twiddlers |
Gerd Isenberg |
Wed May 30, 2007 5:55 pm |
Re: Resource for bit twiddlers |
Pradu Kannan |
Wed May 30, 2007 10:51 pm |
Re: Resource for bit twiddlers |
Gerd Isenberg |
Thu May 31, 2007 6:17 am |
Re: Resource for bit twiddlers |
Pradu Kannan |
Fri Jun 01, 2007 12:16 am |
Re: Resource for bit twiddlers |
Gerd Isenberg |
Fri Jun 01, 2007 8:19 am |
Re: Resource for bit twiddlers |
Gerd Isenberg |
Mon Jun 04, 2007 2:58 pm |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|