示例#1
0
int bitstringHemDistance(int length, uint8 *bstr1, uint8 *bstr2)
{
  int difference = 0; 
  uint8 * bstr1_end = bstr1 + length;
  
#ifdef USE_BUILTIN_POPCOUNT
  int ilength = length / sizeof(POPCNT_TYPE);

  POPCNT_TYPE * ibstr1 = (POPCNT_TYPE *) bstr1;
  POPCNT_TYPE * ibstr2 = (POPCNT_TYPE *) bstr2;
  POPCNT_TYPE * ibstr1_end = ibstr1 + ilength;
  POPCNT_TYPE * ibstr1_end4 = ibstr1_end - (ilength % 4);
  
  while (ibstr1 < ibstr1_end4) {
    difference += POPCNT(*ibstr1++ ^ *ibstr2++);
    difference += POPCNT(*ibstr1++ ^ *ibstr2++);
    difference += POPCNT(*ibstr1++ ^ *ibstr2++);
    difference += POPCNT(*ibstr1++ ^ *ibstr2++);
  }
  
  while (ibstr1 < ibstr1_end) {
    difference += POPCNT(*ibstr1++ ^ *ibstr2++);
  }
  
  bstr1 = (uint8 *) ibstr1;
  bstr2 = (uint8 *) ibstr2;
#endif
  
  while (bstr1 < bstr1_end) {
    difference += number_of_ones[*bstr1++ ^ *bstr2++];
  }

  return difference;
}
示例#2
0
int bitstringIntersectionWeight(int length, uint8 *bstr1, uint8 *bstr2)
{
  int intersect_popcount = 0;
  uint8 * bstr1_end = bstr1 + length;
  
#ifdef USE_BUILTIN_POPCOUNT
  int ilength = length / sizeof(POPCNT_TYPE);

  POPCNT_TYPE * ibstr1 = (POPCNT_TYPE *) bstr1;
  POPCNT_TYPE * ibstr2 = (POPCNT_TYPE *) bstr2;
  POPCNT_TYPE * ibstr1_end = ibstr1 + ilength;
  POPCNT_TYPE * ibstr1_end4 = ibstr1_end - (ilength % 4);
  
  while (ibstr1 < ibstr1_end4) {
    intersect_popcount += POPCNT(*ibstr1++ & *ibstr2++);
    intersect_popcount += POPCNT(*ibstr1++ & *ibstr2++);
    intersect_popcount += POPCNT(*ibstr1++ & *ibstr2++);
    intersect_popcount += POPCNT(*ibstr1++ & *ibstr2++);
  }
  
  while (ibstr1 < ibstr1_end) {
    intersect_popcount += POPCNT(*ibstr1++ & *ibstr2++);
  }
  
  bstr1 = (uint8 *) ibstr1;
  bstr2 = (uint8 *) ibstr2;
#endif
  
  while (bstr1 < bstr1_end) {
    intersect_popcount += number_of_ones[*bstr1++ & *bstr2++];
  }
  
  return intersect_popcount;
}
示例#3
0
int bitstringWeight(int length, uint8 *bstr)
{
  int total_popcount = 0; 
  uint8 * bstr_end = bstr + length;

#ifdef USE_BUILTIN_POPCOUNT
  int ilength = length / sizeof(POPCNT_TYPE);

  POPCNT_TYPE * ibstr = (POPCNT_TYPE *) bstr;
  POPCNT_TYPE * ibstr_end = ibstr + ilength;
  POPCNT_TYPE * ibstr_end4 = ibstr_end - (ilength % 4);
  
  while (ibstr < ibstr_end4) {
    total_popcount += POPCNT(*ibstr++);
    total_popcount += POPCNT(*ibstr++);
    total_popcount += POPCNT(*ibstr++);
    total_popcount += POPCNT(*ibstr++);
  }
  
  while (ibstr < ibstr_end) {
    total_popcount += POPCNT(*ibstr++);
  }
  
  bstr = (uint8 *) ibstr;
#endif
  
  while (bstr < bstr_end) {
    total_popcount += number_of_ones[*bstr++];
  }
  
  return total_popcount;
}
示例#4
0
int bitstringDifferenceWeight(int length, uint8 *bstr1, uint8 *bstr2)
{
  int difference = 0; 
  uint8 * bstr1_end = bstr1 + length;
  
#ifdef USE_BUILTIN_POPCOUNT
  int ilength = length / sizeof(POPCNT_TYPE);

  POPCNT_TYPE ib1;
  POPCNT_TYPE * ibstr1 = (POPCNT_TYPE *) bstr1;
  POPCNT_TYPE * ibstr2 = (POPCNT_TYPE *) bstr2;
  POPCNT_TYPE * ibstr1_end = ibstr1 + ilength;
  POPCNT_TYPE * ibstr1_end4 = ibstr1_end - (ilength % 4);
  
  while (ibstr1 < ibstr1_end4) {
    ib1 = *ibstr1++; difference += POPCNT(ib1 ^ (ib1 | *ibstr2++));
    ib1 = *ibstr1++; difference += POPCNT(ib1 ^ (ib1 | *ibstr2++));
    ib1 = *ibstr1++; difference += POPCNT(ib1 ^ (ib1 | *ibstr2++));
    ib1 = *ibstr1++; difference += POPCNT(ib1 ^ (ib1 | *ibstr2++));
  }
  
  while (ibstr1 < ibstr1_end) {
    ib1 = *ibstr1++; difference += POPCNT(ib1 ^ (ib1 | *ibstr2++));
  }
  
  bstr1 = (uint8 *) ibstr1;
  bstr2 = (uint8 *) ibstr2;
#endif
  
  while (bstr1 < bstr1_end) {
    uint8 b1 = *bstr1++; 
    uint8 b2 = *bstr2++;
    difference += number_of_ones[b1 ^ (b1 | b2)];
  }

  return difference;
}
示例#5
0
bool RobboMake(typePos *Position)
    {
    int va, v2, cp;
    uint32 m;
   Position->Dyn->Hash ^= 0xfa73e65b089c41d2;
    SearchRobboBases = true;
    Eval(Position, -0x7fff0000, 0x7fff0000, 0, 0xff);
   Position->Dyn->Hash ^= 0xfa73e65b089c41d2;
    if (Position->Dyn->exact)
        SearchRobboBases = false;
    else
        SearchRobboBases = true;
    if (!TotalCondition(Position) || !RobboTotalBaseScore(Position, &va))
        return false;
    if (!RobboMove(Position, &m, &v2, &cp))
        return false;
    if (DiskDraw(va))
        {
        Send("info multipv 1 depth 0 score cp 0 pv %s\n", Notate(m, String1[Position->cpu]));

#ifdef Log
		if (WriteLog)
			{
			log_file = fopen(log_filename, "a");
			fprintf(log_file, "info multipv 1 depth 0 score cp 0 pv %s\n", Notate(m, String1[Position->cpu]));
			close_log();
			}
#endif

        RootBestMove = m;
        return true;
        }
    if (DiskLoss(va))
        {
        Send("info multipv 1 depth 0 score cp %d pv %s\n", -28000 + 1000 * POPCNT(Position->OccupiedBW) + v2,
			Notate(m, String1[Position->cpu]));

#ifdef Log
		if (WriteLog)
			{
			log_file = fopen(log_filename, "a");
			fprintf(log_file, "info multipv 1 depth 0 score cp %d pv %s\n", -28000 + 1000 * POPCNT(Position->OccupiedBW) + v2,
				Notate(m, String1[Position->cpu]));
			close_log();
			}
#endif

        RootBestMove = m;
        return true;
        }
    if (DiskWin(va))
        {
        Send("info multipv 1 depth 0 score cp %d pv %s\n", 28000 - 1000 * POPCNT(Position->OccupiedBW) - v2,
			Notate(m, String1[Position->cpu]));

#ifdef Log
		if (WriteLog)
			{
			log_file = fopen(log_filename, "a");
			fprintf(log_file, "info multipv 1 depth 0 score cp %d pv %s\n", 28000 - 1000 * POPCNT(Position->OccupiedBW) - v2,
				Notate(m, String1[Position->cpu]));
			close_log();
			}
#endif

        RootBestMove = m;
        return true;
        }
    return false;
    }
示例#6
0
	unsigned wired;
	struct tlb_entry {
		register_t entryhi;
		register_t entrylo0;
		register_t entrylo1;
		register_t pagemask;
	} entry[MIPS_MAX_TLB_ENTRIES];
};

static struct tlb_state tlb_state[MAXCPU];

#if 0
/*
 * PageMask must increment in steps of 2 bits.
 */
COMPILE_TIME_ASSERT(POPCNT(TLBMASK_MASK) % 2 == 0);
#endif

static inline void
tlb_probe(void)
{
	__asm __volatile ("tlbp" : : : "memory");
	mips_cp0_sync();
}

static inline void
tlb_read(void)
{
	__asm __volatile ("tlbr" : : : "memory");
	mips_cp0_sync();
}
示例#7
0
double bitstringTanimotoSimilarity(int length, uint8 *bstr1, uint8 *bstr2)
{
  double sim;

  int union_popcount = 0;
  int intersect_popcount = 0;
  
  uint8 * bstr1_end = bstr1 + length;

#ifdef USE_BUILTIN_POPCOUNT
  int ilength = length / sizeof(POPCNT_TYPE);

  POPCNT_TYPE * ibstr1 = (POPCNT_TYPE *) bstr1;
  POPCNT_TYPE * ibstr2 = (POPCNT_TYPE *) bstr2;
  POPCNT_TYPE * ibstr1_end = ibstr1 + ilength;
  POPCNT_TYPE * ibstr1_end4 = ibstr1_end - (ilength % 4);

  POPCNT_TYPE ib1, ib2;
  while (ibstr1 < ibstr1_end4) {
    ib1 = *ibstr1++;
    ib2 = *ibstr2++;
    union_popcount += POPCNT(ib1 | ib2);
    intersect_popcount += POPCNT(ib1 & ib2);
    ib1 = *ibstr1++;
    ib2 = *ibstr2++;
    union_popcount += POPCNT(ib1 | ib2);
    intersect_popcount += POPCNT(ib1 & ib2);
    ib1 = *ibstr1++;
    ib2 = *ibstr2++;
    union_popcount += POPCNT(ib1 | ib2);
    intersect_popcount += POPCNT(ib1 & ib2);
    ib1 = *ibstr1++;
    ib2 = *ibstr2++;
    union_popcount += POPCNT(ib1 | ib2);
    intersect_popcount += POPCNT(ib1 & ib2);
  }
  
  while (ibstr1 < ibstr1_end) {
    ib1 = *ibstr1++;
    ib2 = *ibstr2++;
    union_popcount += POPCNT(ib1 | ib2);
    intersect_popcount += POPCNT(ib1 & ib2);
  }
  
  bstr1 = (uint8 *) ibstr1;
  bstr2 = (uint8 *) ibstr2;
#endif
  
  while (bstr1 < bstr1_end) {
    uint8 b1 = *bstr1++;
    uint8 b2 = *bstr2++;
    union_popcount += number_of_ones[ b1 | b2 ];
    intersect_popcount += number_of_ones[ b1 & b2 ];
  }
    
  if (union_popcount != 0) {
    sim = ((double)intersect_popcount) / union_popcount;
  }
  else {
    sim = 1.0;
  }
  
  return sim;
}