예제 #1
0
int board_opening(const board_t * board) {

   int opening;
   int colour;
   const sq_t * ptr;
   int sq, piece;

   ASSERT(board!=NULL);

   opening = 0;

   for (colour = 0; colour < ColourNb; colour++) {

      for (ptr = &board->piece[colour][0]; (sq=*ptr) != SquareNone; ptr++) {
         piece = board->square[sq];
         opening += PST(PIECE_TO_12(piece),SQUARE_TO_64(sq),Opening);
      }

      for (ptr = &board->pawn[colour][0]; (sq=*ptr) != SquareNone; ptr++) {
         piece = board->square[sq];
         opening += PST(PIECE_TO_12(piece),SQUARE_TO_64(sq),Opening);
      }
   }

   return opening;
}
예제 #2
0
파일: make_move.c 프로젝트: Censor/Ivanhoe
static INLINE void MakeBlackOO (typePOS* POSITION, int to)
{
  if (to == G8)
    {
      bBitboardOcc ^= F8H8;
      bBitboardR ^= F8H8;
      POSITION->OccupiedBW ^= F8H8;
#ifndef MAGIC_BITBOARDS
      POSITION->OccupiedL90 ^= F8H8Left90;
      POSITION->OccupiedL45 ^= F8H8Left45;
      POSITION->OccupiedR45 ^= F8H8Right45;
#endif
      POSITION->DYN->STATIC += PST (bEnumR, F8) - PST (bEnumR, H8);
      POSITION->DYN->HASH ^= Zobrist (bEnumR, F8) ^ Zobrist (bEnumR, H8);
      POSITION->sq[H8] = 0;
      POSITION->sq[F8] = bEnumR;
    }
  else if (to == C8)
    {
      bBitboardOcc ^= A8D8;
      bBitboardR ^= A8D8;
      POSITION->OccupiedBW ^= A8D8;
#ifndef MAGIC_BITBOARDS
      POSITION->OccupiedL90 ^= A8D8Left90;
      POSITION->OccupiedL45 ^= A8D8Left45;
      POSITION->OccupiedR45 ^= A8D8Right45;
#endif
      POSITION->DYN->STATIC += PST (bEnumR, D8) - PST (bEnumR, A8);
      POSITION->DYN->HASH ^= Zobrist (bEnumR, A8) ^ Zobrist (bEnumR, D8);
      POSITION->sq[A8] = 0;
      POSITION->sq[D8] = bEnumR;
    }
}
예제 #3
0
int board_endgame(const board_t * board) {

   int endgame;
   int colour;
   const sq_t * ptr;
   int sq, piece;

   ASSERT(board!=NULL);

   endgame = 0;

   for (colour = 0; colour < ColourNb; colour++) {

      for (ptr = &board->piece[colour][0]; (sq=*ptr) != SquareNone; ptr++) {
         piece = board->square[sq];
         endgame += PST(PIECE_TO_12(piece),SQUARE_TO_64(sq),Endgame);
      }

      for (ptr = &board->pawn[colour][0]; (sq=*ptr) != SquareNone; ptr++) {
         piece = board->square[sq];
         endgame += PST(PIECE_TO_12(piece),SQUARE_TO_64(sq),Endgame);
      }
   }

   return endgame;
}
예제 #4
0
파일: make_move.c 프로젝트: Censor/Ivanhoe
static INLINE void MakeWhiteOO (typePOS* POSITION, int to)
{
  if (to == G1)
    {
      wBitboardOcc ^= F1H1;
      wBitboardR ^= F1H1;
      POSITION->OccupiedBW ^= F1H1;
#ifndef MAGIC_BITBOARDS
      POSITION->OccupiedL90 ^= F1H1Left90;
      POSITION->OccupiedL45 ^= F1H1Left45;
      POSITION->OccupiedR45 ^= F1H1Right45;
#endif
      POSITION->DYN->STATIC += PST (wEnumR, F1) - PST (wEnumR, H1);
      POSITION->DYN->HASH ^= Zobrist (wEnumR, F1) ^ Zobrist (wEnumR, H1);
      POSITION->sq[H1] = 0;
      POSITION->sq[F1] = wEnumR;
    }
  else if (to == C1)
    {
      wBitboardOcc ^= A1D1;
      wBitboardR ^= A1D1;
      POSITION->OccupiedBW ^= A1D1;
#ifndef MAGIC_BITBOARDS
      POSITION->OccupiedL90 ^= A1D1Left90;
      POSITION->OccupiedL45 ^= A1D1Left45;
      POSITION->OccupiedR45 ^= A1D1Right45;
#endif
      POSITION->DYN->STATIC += PST (wEnumR, D1) - PST (wEnumR, A1);
      POSITION->DYN->HASH ^= Zobrist (wEnumR, A1) ^ Zobrist (wEnumR, D1);
      POSITION->sq[A1] = 0;
      POSITION->sq[D1] = wEnumR;
    }
}
예제 #5
0
static INLINE void MakeWhiteOO(typePos *Position, int to)
    {
    if (to == G1)
        {
        wBitboardOcc ^= F1H1;
        wBitboardR ^= F1H1;
        Position->OccupiedBW ^= F1H1;
        Position->Dyn->Static += PST(wEnumR, F1) - PST(wEnumR, H1);
        Position->Dyn->Hash ^= Hash(wEnumR, F1) ^ Hash(wEnumR, H1);
        Position->sq[H1] = 0;
        Position->sq[F1] = wEnumR;
        }
    else if (to == C1)
        {
        wBitboardOcc ^= A1D1;
        wBitboardR ^= A1D1;
        Position->OccupiedBW ^= A1D1;
        Position->Dyn->Static += PST(wEnumR, D1) - PST(wEnumR, A1);
        Position->Dyn->Hash ^= Hash(wEnumR, A1) ^ Hash(wEnumR, D1);
        Position->sq[A1] = 0;
        Position->sq[D1] = wEnumR;
        }
    }
예제 #6
0
static INLINE void MakeBlackOO(typePos *Position, int to)
    {
    if (to == G8)
        {
        bBitboardOcc ^= F8H8;
        bBitboardR ^= F8H8;
        Position->OccupiedBW ^= F8H8;
        Position->Dyn->Static += PST(bEnumR, F8) - PST(bEnumR, H8);
        Position->Dyn->Hash ^= Hash(bEnumR, F8) ^ Hash(bEnumR, H8);
        Position->sq[H8] = 0;
        Position->sq[F8] = bEnumR;
        }
    else if (to == C8)
        {
        bBitboardOcc ^= A8D8;
        bBitboardR ^= A8D8;
        Position->OccupiedBW ^= A8D8;
        Position->Dyn->Static += PST(bEnumR, D8) - PST(bEnumR, A8);
        Position->Dyn->Hash ^= Hash(bEnumR, A8) ^ Hash(bEnumR, D8);
        Position->sq[A8] = 0;
        Position->sq[D8] = bEnumR;
        }
    }
예제 #7
0
static INLINE void Castle960White( typePos *Position, int move, int to, int fr )
    {
    int fl;
   Position->Dyn++;
   Position->Dyn->reversible++;
    RevCastle(Position);
   Position->Dyn->move = move;
    fl = Position->Dyn->oo & 0xc;
   Position->Dyn->Hash ^= HashCastling[Position->Dyn->oo ^ fl];
   Position->Dyn->Hash ^= HashWTM;
   Position->Dyn->PawnHash ^= HashCastling[Position->Dyn->oo ^ fl];
   Position->Dyn->oo = fl;

    if (Position->Dyn->ep)
        {
       Position->Dyn->Hash ^= HashEP[Position->Dyn->ep & 7];
       Position->Dyn->ep = 0;
        }
   Position->sq[to] = 0;
   Position->sq[fr] = 0;
    wBitboardK ^= SqSet[fr];
    wBitboardR ^= SqSet[to];
    wBitboardOcc ^= SqSet[to] | SqSet[fr];
   Position->wtm ^= 1;
   Position->height++;
   Position->Dyn->Hash ^= Hash(wEnumK, fr) ^ Hash(wEnumR, to);
   Position->Dyn->PawnHash ^= Hash(wEnumK, fr);
   Position->Dyn->Static -= PST(wEnumK, fr) + PST(wEnumR, to);

    if (to > fr)
        {
       Position->sq[F1] = wEnumR;
       Position->sq[G1] = wEnumK;
        wBitboardOcc |= SqSet[F1] | SqSet[G1];
        wBitboardK |= SqSet[G1];
        wBitboardR |= SqSet[F1];
       Position->Dyn->Hash ^= Hash(wEnumK, G1) ^ Hash(wEnumR, F1);
       Position->Dyn->PawnHash ^= Hash(wEnumK, G1);
       Position->wKsq = G1;
       Position->Dyn->Static += PST(wEnumK, G1) + PST(wEnumR, F1);
        }

    if (to < fr)
        {
       Position->sq[D1] = wEnumR;
       Position->sq[C1] = wEnumK;
        wBitboardOcc |= SqSet[D1] | SqSet[C1];
        wBitboardK |= SqSet[C1];
        wBitboardR |= SqSet[D1];
       Position->Dyn->Hash ^= Hash(wEnumK, C1) ^ Hash(wEnumR, D1);
       Position->Dyn->PawnHash ^= Hash(wEnumK, C1);
       Position->wKsq = C1;
       Position->Dyn->Static += PST(wEnumK, C1) + PST(wEnumR, D1);
        }
   Position->OccupiedBW = wBitboardOcc | bBitboardOcc;
   Position->Stack[++ (Position->StackHeight)] = Position->Dyn->Hash;
    }
예제 #8
0
static INLINE void Castle960Black( typePos *Position, int move, int to, int fr )
    {
    int fl;
   Position->Dyn++;
   Position->Dyn->reversible++;
    RevCastle(Position);
   Position->Dyn->move = move;
    fl = Position->Dyn->oo & 0x3;
   Position->Dyn->Hash ^= HashCastling[Position->Dyn->oo ^ fl];
   Position->Dyn->Hash ^= HashWTM;
   Position->Dyn->PawnHash ^= HashCastling[Position->Dyn->oo ^ fl];
   Position->Dyn->oo = fl;

    if (Position->Dyn->ep)
        {
       Position->Dyn->Hash ^= HashEP[Position->Dyn->ep & 7];
       Position->Dyn->ep = 0;
        }
   Position->sq[to] = 0;
   Position->sq[fr] = 0;
    bBitboardK ^= SqSet[fr];
    bBitboardR ^= SqSet[to];
    bBitboardOcc ^= SqSet[to] | SqSet[fr];
   Position->wtm ^= 1;
   Position->height++;
   Position->Dyn->Hash ^= Hash(bEnumK, fr) ^ Hash(bEnumR, to);
   Position->Dyn->PawnHash ^= Hash(bEnumK, fr);
   Position->Dyn->Static -= PST(bEnumK, fr) + PST(bEnumR, to);

    if (to > fr)
        {
       Position->sq[F8] = bEnumR;
       Position->sq[G8] = bEnumK;
        bBitboardOcc |= SqSet[F8] | SqSet[G8];
        bBitboardK |= SqSet[G8];
        bBitboardR |= SqSet[F8];
       Position->Dyn->Hash ^= Hash(bEnumK, G8) ^ Hash(bEnumR, F8);
       Position->Dyn->PawnHash ^= Hash(bEnumK, G8);
       Position->bKsq = G8;
       Position->Dyn->Static += PST(bEnumK, G8) + PST(bEnumR, F8);
        }

    if (to < fr)
        {
       Position->sq[D8] = bEnumR;
       Position->sq[C8] = bEnumK;
        bBitboardOcc |= SqSet[D8] | SqSet[C8];
        bBitboardK |= SqSet[C8];
        bBitboardR |= SqSet[D8];
       Position->Dyn->Hash ^= Hash(bEnumK, C8) ^ Hash(bEnumR, D8);
       Position->Dyn->PawnHash ^= Hash(bEnumK, C8);
       Position->bKsq = C8;
       Position->Dyn->Static += PST(bEnumK, C8) + PST(bEnumR, D8);
        }
   Position->OccupiedBW = wBitboardOcc | bBitboardOcc; 
   Position->Stack[++ (Position->StackHeight)] = Position->Dyn->Hash;
    }
예제 #9
0
파일: make_move.c 프로젝트: Censor/Ivanhoe
static INLINE void Castle960Black (typePOS* POSITION, int move, int to, int fr)
{
  int fl;
  POSITION->DYN++;
  REV_HASH (POSITION);
  POSITION->DYN->reversible++;
  REV_CASTLE (POSITION);
  POSITION->DYN->move = move;
  fl = POSITION->DYN->oo & 0x3;
  POSITION->DYN->HASH ^= ZobristCastling[POSITION->DYN->oo ^ fl];
  POSITION->DYN->HASH ^= ZobristWTM;
  POSITION->DYN->PAWN_HASH ^= ZobristCastling[POSITION->DYN->oo ^ fl];
  POSITION->DYN->oo = fl;
  if (POSITION->DYN->ep)
    {
      POSITION->DYN->HASH ^= ZobristEP[POSITION->DYN->ep & 7];
      POSITION->DYN->ep = 0;
    }
  POSITION->sq[to] = 0;
  POSITION->sq[fr] = 0;
  bBitboardK ^= SqSet[fr];
  bBitboardR ^= SqSet[to];
  bBitboardOcc ^= SqSet[to] | SqSet[fr];
  POSITION->wtm ^= 1;
  POSITION->height++;
  POSITION->DYN->HASH ^= Zobrist (bEnumK, fr) ^ Zobrist (bEnumR, to);
  POSITION->DYN->PAWN_HASH ^= Zobrist (bEnumK, fr);
  POSITION->DYN->STATIC -= PST (bEnumK, fr) + PST (bEnumR, to);
  if (to > fr)
    {
      POSITION->sq[F8] = bEnumR;
      POSITION->sq[G8] = bEnumK;
      bBitboardOcc |= SqSet[F8] | SqSet[G8];
      bBitboardK |= SqSet[G8];
      bBitboardR |= SqSet[F8];
      POSITION->DYN->HASH ^= Zobrist (bEnumK, G8) ^ Zobrist (bEnumR, F8);
      POSITION->DYN->PAWN_HASH ^= Zobrist (bEnumK, G8);
      POSITION->bKsq = G8;
      POSITION->DYN->STATIC += PST (bEnumK, G8) + PST (bEnumR, F8);
    }
  if (to < fr)
    {
      POSITION->sq[D8] = bEnumR;
      POSITION->sq[C8] = bEnumK;
      bBitboardOcc |= SqSet[D8] | SqSet[C8];
      bBitboardK |= SqSet[C8];
      bBitboardR |= SqSet[D8];
      POSITION->DYN->HASH ^= Zobrist (bEnumK, C8) ^ Zobrist (bEnumR, D8);
      POSITION->DYN->PAWN_HASH ^= Zobrist (bEnumK, C8);
      POSITION->bKsq = C8;
      POSITION->DYN->STATIC += PST (bEnumK, C8) + PST (bEnumR, D8);
    }
  POSITION->OccupiedBW = wBitboardOcc | bBitboardOcc; /* HACK */
  POSITION->STACK[++(POSITION->StackHeight)] = POSITION->DYN->HASH;
  REV_HASH (POSITION);
  VALIDATE (POSITION, 0, move);
}
예제 #10
0
파일: make_move.c 프로젝트: Censor/Ivanhoe
static INLINE void Castle960White (typePOS* POSITION, int move, int to, int fr)
{
  int fl;
  POSITION->DYN++;
  REV_HASH (POSITION);
  POSITION->DYN->reversible++;
  REV_CASTLE (POSITION);
  POSITION->DYN->move = move;
  fl = POSITION->DYN->oo & 0xc;
  POSITION->DYN->HASH ^= ZobristCastling[POSITION->DYN->oo ^ fl];
  POSITION->DYN->HASH ^= ZobristWTM;
  POSITION->DYN->PAWN_HASH ^= ZobristCastling[POSITION->DYN->oo ^ fl];
  POSITION->DYN->oo = fl;
  if (POSITION->DYN->ep)
    {
      POSITION->DYN->HASH ^= ZobristEP[POSITION->DYN->ep & 7];
      POSITION->DYN->ep = 0;
    }
  POSITION->sq[to] = 0;
  POSITION->sq[fr] = 0;
  wBitboardK ^= SqSet[fr];
  wBitboardR ^= SqSet[to];
  wBitboardOcc ^= SqSet[to] | SqSet[fr];
  POSITION->wtm ^= 1;
  POSITION->height++;
  POSITION->DYN->HASH ^= Zobrist (wEnumK, fr) ^ Zobrist (wEnumR, to);
  POSITION->DYN->PAWN_HASH ^= Zobrist (wEnumK, fr);
  POSITION->DYN->STATIC -= PST (wEnumK, fr) + PST (wEnumR, to);
  if (to > fr)
    {
      POSITION->sq[F1] = wEnumR;
      POSITION->sq[G1] = wEnumK;
      wBitboardOcc |= SqSet[F1] | SqSet[G1];
      wBitboardK |= SqSet[G1];
      wBitboardR |= SqSet[F1];
      POSITION->DYN->HASH ^= Zobrist (wEnumK, G1) ^ Zobrist (wEnumR, F1);
      POSITION->DYN->PAWN_HASH ^= Zobrist (wEnumK, G1);
      POSITION->wKsq = G1;
      POSITION->DYN->STATIC += PST (wEnumK, G1) + PST (wEnumR, F1);
    }
  if (to < fr)
    {
      POSITION->sq[D1] = wEnumR;
      POSITION->sq[C1] = wEnumK;
      wBitboardOcc |= SqSet[D1] | SqSet[C1];
      wBitboardK |= SqSet[C1];
      wBitboardR |= SqSet[D1];
      POSITION->DYN->HASH ^= Zobrist (wEnumK, C1) ^ Zobrist (wEnumR, D1);
      POSITION->DYN->PAWN_HASH ^= Zobrist (wEnumK, C1);
      POSITION->wKsq = C1;
      POSITION->DYN->STATIC += PST (wEnumK, C1) + PST (wEnumR, D1);
    }
  POSITION->OccupiedBW = wBitboardOcc | bBitboardOcc; /* HACK */
  POSITION->STACK[++(POSITION->StackHeight)] = POSITION->DYN->HASH;
  REV_HASH (POSITION);
  VALIDATE (POSITION, 0, move);
}
예제 #11
0
static void do_emu(struct info * info)
{
	unsigned short code;
	temp_real tmp;
	char * address;

	if (I387.cwd & I387.swd & 0x3f)
		I387.swd |= 0x8000;
	else
		I387.swd &= 0x7fff;
	ORIG_EIP = EIP;
/* 0x0007 means user code space */
	if (CS != 0x000F) {
		printk("math_emulate: %04x:%08x\n\r",CS,EIP);
		panic("Math emulation needed in kernel");
	}
	code = get_fs_word((unsigned short *) EIP);
	bswapw(code);
	code &= 0x7ff;
	I387.fip = EIP;
	*(unsigned short *) &I387.fcs = CS;
	*(1+(unsigned short *) &I387.fcs) = code;
	EIP += 2;
	switch (code) {
		case 0x1d0: /* fnop */
			return;
		case 0x1d1: case 0x1d2: case 0x1d3:
		case 0x1d4: case 0x1d5: case 0x1d6: case 0x1d7:
			math_abort(info,1<<(SIGILL-1));
		case 0x1e0:
			ST(0).exponent ^= 0x8000;
			return;
		case 0x1e1:
			ST(0).exponent &= 0x7fff;
			return;
		case 0x1e2: case 0x1e3:
			math_abort(info,1<<(SIGILL-1));
		case 0x1e4:
			ftst(PST(0));
			return;
		case 0x1e5:
			printk("fxam not implemented\n\r");
			math_abort(info,1<<(SIGILL-1));
		case 0x1e6: case 0x1e7:
			math_abort(info,1<<(SIGILL-1));
		case 0x1e8:
			fpush();
			ST(0) = CONST1;
			return;
		case 0x1e9:
			fpush();
			ST(0) = CONSTL2T;
			return;
		case 0x1ea:
			fpush();
			ST(0) = CONSTL2E;
			return;
		case 0x1eb:
			fpush();
			ST(0) = CONSTPI;
			return;
		case 0x1ec:
			fpush();
			ST(0) = CONSTLG2;
			return;
		case 0x1ed:
			fpush();
			ST(0) = CONSTLN2;
			return;
		case 0x1ee:
			fpush();
			ST(0) = CONSTZ;
			return;
		case 0x1ef:
			math_abort(info,1<<(SIGILL-1));
		case 0x1f0: case 0x1f1: case 0x1f2: case 0x1f3:
		case 0x1f4: case 0x1f5: case 0x1f6: case 0x1f7:
		case 0x1f8: case 0x1f9: case 0x1fa: case 0x1fb:
		case 0x1fc: case 0x1fd: case 0x1fe: case 0x1ff:
			printk("%04x fxxx not implemented\n\r",code + 0xc800);
			math_abort(info,1<<(SIGILL-1));
		case 0x2e9:
			fucom(PST(1),PST(0));
			fpop(); fpop();
			return;
		case 0x3d0: case 0x3d1:
			return;
		case 0x3e2:
			I387.swd &= 0x7f00;
			return;
		case 0x3e3:
			I387.cwd = 0x037f;
			I387.swd = 0x0000;
			I387.twd = 0x0000;
			return;
		case 0x3e4:
			return;
		case 0x6d9:
			fcom(PST(1),PST(0));
			fpop(); fpop();
			return;
		case 0x7e0:
			*(short *) &EAX = I387.swd;
			return;
	}
	switch (code >> 3) {
		case 0x18:
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x19:
			fmul(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1a:
			fcom(PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1b:
			fcom(PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			fpop();
			return;
		case 0x1c:
			real_to_real(&ST(code & 7),&tmp);
			tmp.exponent ^= 0x8000;
			fadd(PST(0),&tmp,&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1d:
			ST(0).exponent ^= 0x8000;
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1e:
			fdiv(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1f:
			fdiv(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x38:
			fpush();
			ST(0) = ST((code & 7)+1);
			return;
		case 0x39:
			fxchg(&ST(0),&ST(code & 7));
			return;
		case 0x3b:
			ST(code & 7) = ST(0);
			fpop();
			return;
		case 0x98:
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x99:
			fmul(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x9a:
			fcom(PST(code & 7),PST(0));
			return;
		case 0x9b:
			fcom(PST(code & 7),PST(0));
			fpop();
			return;			
		case 0x9c:
			ST(code & 7).exponent ^= 0x8000;
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x9d:
			real_to_real(&ST(0),&tmp);
			tmp.exponent ^= 0x8000;
			fadd(PST(code & 7),&tmp,&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x9e:
			fdiv(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x9f:
			fdiv(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0xb8:
			printk("ffree not implemented\n\r");
			math_abort(info,1<<(SIGILL-1));
		case 0xb9:
			fxchg(&ST(0),&ST(code & 7));
			return;
		case 0xba:
			ST(code & 7) = ST(0);
			return;
		case 0xbb:
			ST(code & 7) = ST(0);
			fpop();
			return;
		case 0xbc:
			fucom(PST(code & 7),PST(0));
			return;
		case 0xbd:
			fucom(PST(code & 7),PST(0));
			fpop();
			return;
		case 0xd8:
			fadd(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xd9:
			fmul(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xda:
			fcom(PST(code & 7),PST(0));
			fpop();
			return;
		case 0xdc:
			ST(code & 7).exponent ^= 0x8000;
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xdd:
			real_to_real(&ST(0),&tmp);
			tmp.exponent ^= 0x8000;
			fadd(PST(code & 7),&tmp,&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xde:
			fdiv(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xdf:
			fdiv(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xf8:
			printk("ffree not implemented\n\r");
			math_abort(info,1<<(SIGILL-1));
			fpop();
			return;
		case 0xf9:
			fxchg(&ST(0),&ST(code & 7));
			return;
		case 0xfa:
		case 0xfb:
			ST(code & 7) = ST(0);
			fpop();
			return;
	}
	switch ((code>>3) & 0xe7) {
		case 0x22:
			put_short_real(PST(0),info,code);
			return;
		case 0x23:
			put_short_real(PST(0),info,code);
			fpop();
			return;
		case 0x24:
			address = ea(info,code);
			for (code = 0 ; code < 7 ; code++) {
				((long *) & I387)[code] =
				   get_fs_long((unsigned long *) address);
				address += 4;
			}
			return;
		case 0x25:
			address = ea(info,code);
			*(unsigned short *) &I387.cwd =
				get_fs_word((unsigned short *) address);
			return;
		case 0x26:
			address = ea(info,code);
			verify_area(address,28);
			for (code = 0 ; code < 7 ; code++) {
				put_fs_long( ((long *) & I387)[code],
					(unsigned long *) address);
				address += 4;
			}
			return;
		case 0x27:
			address = ea(info,code);
			verify_area(address,2);
			put_fs_word(I387.cwd,(short *) address);
			return;
		case 0x62:
			put_long_int(PST(0),info,code);
			return;
		case 0x63:
			put_long_int(PST(0),info,code);
			fpop();
			return;
		case 0x65:
			fpush();
			get_temp_real(&tmp,info,code);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x67:
			put_temp_real(PST(0),info,code);
			fpop();
			return;
		case 0xa2:
			put_long_real(PST(0),info,code);
			return;
		case 0xa3:
			put_long_real(PST(0),info,code);
			fpop();
			return;
		case 0xa4:
			address = ea(info,code);
			for (code = 0 ; code < 27 ; code++) {
				((long *) & I387)[code] =
				   get_fs_long((unsigned long *) address);
				address += 4;
			}
			return;
		case 0xa6:
			address = ea(info,code);
			verify_area(address,108);
			for (code = 0 ; code < 27 ; code++) {
				put_fs_long( ((long *) & I387)[code],
					(unsigned long *) address);
				address += 4;
			}
			I387.cwd = 0x037f;
			I387.swd = 0x0000;
			I387.twd = 0x0000;
			return;
		case 0xa7:
			address = ea(info,code);
			verify_area(address,2);
			put_fs_word(I387.swd,(short *) address);
			return;
		case 0xe2:
			put_short_int(PST(0),info,code);
			return;
		case 0xe3:
			put_short_int(PST(0),info,code);
			fpop();
			return;
		case 0xe4:
			fpush();
			get_BCD(&tmp,info,code);
			real_to_real(&tmp,&ST(0));
			return;
		case 0xe5:
			fpush();
			get_longlong_int(&tmp,info,code);
			real_to_real(&tmp,&ST(0));
			return;
		case 0xe6:
			put_BCD(PST(0),info,code);
			fpop();
			return;
		case 0xe7:
			put_longlong_int(PST(0),info,code);
			fpop();
			return;
	}
	switch (code >> 9) {
		case 0:
			get_short_real(&tmp,info,code);
			break;
		case 1:
			get_long_int(&tmp,info,code);
			break;
		case 2:
			get_long_real(&tmp,info,code);
			break;
		case 4:
			get_short_int(&tmp,info,code);
	}
	switch ((code>>3) & 0x27) {
		case 0:
			fadd(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 1:
			fmul(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 2:
			fcom(&tmp,PST(0));
			return;
		case 3:
			fcom(&tmp,PST(0));
			fpop();
			return;
		case 4:
			tmp.exponent ^= 0x8000;
			fadd(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 5:
			ST(0).exponent ^= 0x8000;
			fadd(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 6:
			fdiv(PST(0),&tmp,&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 7:
			fdiv(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
	}
	if ((code & 0x138) == 0x100) {
			fpush();
			real_to_real(&tmp,&ST(0));
			return;
	}
	printk("Unknown math-insns: %04x:%08x %04x\n\r",CS,EIP,code);
	math_abort(info,1<<(SIGFPE-1));
}
예제 #12
0
void FindIntRange(struct BeamlineType *bl)
{
//  int fr_mat[2][2]; // matrix for utilisation results
  double yedge = 1.0E-3;   // start values
  double zedge = 1.0E-3;
  double ff;
  int i, n, nonzeros, imodus;  
  int ianzy0,ianzz0;
  double y1, y2, z1, z2;
  //struct PSDType *psdp;  
  struct PSImageType *psip;
  struct PSImageType backup_psip; 
  
#ifdef DEBUG  
  printf("DEBUG: enter [%s]:FindIntRange()\n", __FILE__);
#endif 

  // backup input struct in case we can't obtain reasonable results
  psip = (struct PSImageType *)bl->RTSource.Quellep;
  memcpy(&backup_psip, psip, sizeof(struct PSImageType));
  
  // use only one gridpoint and central ray for test procedure
  psip->ymin = psip->ymax = psip->zmin = psip->zmax = 0.0;  
  psip->iy = psip->iz = 1;

  ianzy0 = bl->BLOptions.xi.ianzy0;
  ianzz0 = bl->BLOptions.xi.ianzz0;
  
  imodus = 2;
    
  if(imodus == 1)
    {
      // simple loop approach (fixed step size)
      for (i=0; i<100; i++)
	{
	  nonzeros = 0;
	  
	  y1 = -yedge+ i* 1E-4;
	  y2 = -y1;
	  
	  bl->BLOptions.xi.ymin = y1;
	  bl->BLOptions.xi.ymax = y2;
	  
	  PST(bl);
	  
	  
	  // pointer to simpsons data and vector length
	  //psdp = (struct PSDType *)bl->RESULT.RESp;
	  
	  // determine unused (near zero) percentage of result   
	  for (n=0; n<ianzy0; n++) 
	    {
	      double c2y = bl->simpre[8* n+ 5];
	      if (fabs(c2y) >= 1E-10) nonzeros++;
	    }
	  printf("Autorange: pass %d, utilisation: %d\n", i, nonzeros);
	  
	  if (nonzeros == ianzy0) break;           
	} // for loop 
    } // imodus = 1
  
  if(imodus == 2)
    {
      // more effective strategy (variable step size)
      
      nonzeros = ianzy0;
      //   y1 = -yedge/2.;
      //   y2 = -y1; 
      
      y1= bl->BLOptions.xi.ymin;
      y2= bl->BLOptions.xi.ymax; 
      
      while (nonzeros == ianzy0)  // while 1
	{
	  // printf("Autorange ya: ymin %d, ymax  %d, nonzeros: %d\n", y1, y2, nonzeros);  
	  y1=y1*2.;
	  y2=y2*2.;
	  
	  bl->BLOptions.xi.ymin = y1;
	  bl->BLOptions.xi.ymax = y2;
	  
	  PST(bl);
	  
	  // determine unused (near zero) percentage of result
	  // pointer to simpsons data and vector length
	  //psdp = (struct PSDType *)bl->RESULT.RESp;
	  nonzeros=0;
	  for (n=0; n<ianzy0; n++) 
	    {
	      double c2y = bl->simpre[8*n+5];
	      if (fabs(c2y) >= 1E-10) nonzeros++;
	    }
	  
	  printf("===== Autorange ya =======: ymin %e, ymax %e, nonzeros: %d\n", y1, y2, nonzeros);  
	  
          
	}  // end while 1
      
      while (nonzeros*2 < ianzy0) // while 2
	{
	  y1=y1/2.;
	  y2=y2/2.;
	  
	  bl->BLOptions.xi.ymin = y1;
	  bl->BLOptions.xi.ymax = y2;
	  
	  PST(bl);
	  
	  // determine unused (near zero) percentage of result
	  // pointer to simpsons data and vector length
	  //psdp = (struct PSDType *)bl->RESULT.RESp;
	  nonzeros=0;
	  for (n=0; n<ianzy0; n++) 
	    {
	      double c2y = bl->simpre[8*n+5];
	      if (fabs(c2y) >= 1E-10) nonzeros++;
	    }
	  printf("===== Autorange yb =======: ymin %e, ymax %e, nonzeros: %d\n", y1, y2, nonzeros);     
	  
	}  // end while 2
      
      ff=1.1* ((double) nonzeros / (double) ianzy0);
      y1=y1*ff;
      y2=y2*ff;  
      bl->BLOptions.xi.ymin = y1;
      bl->BLOptions.xi.ymax = y2; 
      
    } // end modus = 2
  
  if(imodus == 1)
    {
      // loop for dz
      // dz should be small enough so that plots contains only zeroes,
      // as the plots correspond to left/right-most edge 
      for (i=0; i<100; i++)
	{
	  int nonzeros_l = 0;
	  int nonzeros_r = 0;
	  int nonzeros_i = 0;
	  
	  z1 = -zedge+i*1E-4;
	  z2 = -z1;
	  
	  bl->BLOptions.xi.zmin = z1;
	  bl->BLOptions.xi.zmax = z2;
	  
	  PST(bl);
	  
	  // determine unused (near zero) percentage of result
	  // pointer to simpsons data and vector length
	  //psdp = (struct PSDType *)bl->RESULT.RESp;
	  for (n=0; n<ianzy0; n++) 
	    {
	      double c1y = bl->simpre[8*n+4]; // upper left
	      double c3y = bl->simpre[8*n+6]; // lower left
	      double c4y = bl->simpre[8*n+7]; // lower right (yellow)
	      
	      if (fabs(c1y) >= 1E-10) nonzeros_l++;
	      if (fabs(c3y) >= 1E-10) nonzeros_r++;
	      if (fabs(c3y) >= 1E-10) nonzeros_i++;
	    }
	  
	  printf("Autorange z: pass %d, utilisation: %d, %d, %d\n", i, nonzeros_l, nonzeros_r, nonzeros_i);
	  
	  if ((nonzeros_l == 0) && (nonzeros_r == 0) && (nonzeros_i == ianzy0)) break;      
	  if ((nonzeros_l > 0) || (nonzeros_r > 0)) {z1 -= 1E-4; z2 = -z1; break;};          
	}  
      
      bl->BLOptions.xi.zmin = z1;
      bl->BLOptions.xi.zmax = z2;
      
    } // end imodus = 1
  
  
  if(imodus == 2)
    {
      // more effective strategy (variable step size)
      
      nonzeros = ianzz0;
      
      z1= bl->BLOptions.xi.zmin;
      z2= bl->BLOptions.xi.zmax; 
      
      while (nonzeros == ianzz0)  // while 1
	{
	  // printf("Autorange ya: ymin %d, ymax  %d, nonzeros: %d\n", y1, y2, nonzeros);  
	  z1=z1*2.;
	  z2=z2*2.;
	  
	  bl->BLOptions.xi.zmin = z1;
	  bl->BLOptions.xi.zmax = z2;
	  
	  PST(bl);
	  
	  // determine unused (near zero) percentage of result
	  // pointer to simpsons data and vector length
	  //psdp = (struct PSDType *)bl->RESULT.RESp;
	  nonzeros=0;
	  for (n=0; n<ianzz0; n++) 
	    {
	      double c4y = bl->simpre[8*n+7];
	      if (fabs(c4y) >= 1E-10) nonzeros++;
	    }
	  
	  printf("===== Autorange za =======: zmin %e, zmax %e, nonzeros: %d\n", z1, z2, nonzeros);  
	  
          
	}  // end while 1
      
      while (nonzeros*2 < ianzz0) // while 2
	{
	  z1=z1/2.;
	  z2=z2/2.;
	  
	  bl->BLOptions.xi.zmin = z1;
	  bl->BLOptions.xi.zmax = z2;
	  
	  PST(bl);
	  
	  // determine unused (near zero) percentage of result
	  // pointer to simpsons data and vector length
	  //psdp = (struct PSDType *)bl->RESULT.RESp;
	  nonzeros=0;
	  for (n=0; n<ianzz0; n++) 
	    {
	      double c4y = bl->simpre[8*n+7];
	      if (fabs(c4y) >= 1E-10) nonzeros++;
	    }
	  printf("===== Autorange zb =======: zmin %e, zmax %e, nonzeros: %d\n", z1, z2, nonzeros);     
	  
	}  // end while 2
      
      ff=1.1* ((double) nonzeros / (double) ianzz0);
      z1=z1*ff;
      z2=z2*ff;  
      bl->BLOptions.xi.zmin = z1;
      bl->BLOptions.xi.zmax = z2;
      
    } // end modus = 2
  
  printf("Autorange final: best set found: (%.2f, %.2f, %.2f, %.2f)mrad\n", y1*1E3, y2*1E3, z1*1E3, z2*1E3);
  
  //restoring range struct
  memcpy(psip, &backup_psip, sizeof(struct PSImageType));
}
예제 #13
0
static int
math_emulate(struct trapframe * info)
{
	unsigned short code;
	temp_real tmp;
	char * address;
	u_long oldeip;

	/* ever used fp? */
	if ((((struct pcb *)curproc->p_addr)->pcb_flags & FP_SOFTFP) == 0) {
		((struct pcb *)curproc->p_addr)->pcb_flags |= FP_SOFTFP;
		I387.cwd = 0x037f;
		I387.swd = 0x0000;
		I387.twd = 0x0000;
	}

	if (I387.cwd & I387.swd & 0x3f)
		I387.swd |= 0x8000;
	else
		I387.swd &= 0x7fff;
	oldeip = info->tf_eip;
/* 0x001f means user code space */
	if ((u_short)info->tf_cs != 0x001F) {
		printf("math_emulate: %04x:%08lx\n", (u_short)info->tf_cs,
			oldeip);
		panic("?Math emulation needed in kernel?");
	}
	code = get_fs_word((unsigned short *) oldeip);
	bswapw(code);
	code &= 0x7ff;
	I387.fip = oldeip;
	*(unsigned short *) &I387.fcs = (u_short) info->tf_cs;
	*(1+(unsigned short *) &I387.fcs) = code;
	info->tf_eip += 2;
	switch (code) {
		case 0x1d0: /* fnop */
			return(0);
		case 0x1d1: case 0x1d2: case 0x1d3:  /* fst to 32-bit mem */
		case 0x1d4: case 0x1d5: case 0x1d6: case 0x1d7:
			math_abort(info,SIGILL);
		case 0x1e0: /* fchs */
			ST(0).exponent ^= 0x8000;
			return(0);
		case 0x1e1: /* fabs */
			ST(0).exponent &= 0x7fff;
			return(0);
		case 0x1e2: case 0x1e3:
			math_abort(info,SIGILL);
		case 0x1e4: /* ftst */
			ftst(PST(0));
			return(0);
		case 0x1e5: /* fxam */
			printf("fxam not implemented\n");
			math_abort(info,SIGILL);
		case 0x1e6: case 0x1e7: /* fldenv */
			math_abort(info,SIGILL);
		case 0x1e8: /* fld1 */
			fpush();
			ST(0) = CONST1;
			return(0);
		case 0x1e9: /* fld2t */
			fpush();
			ST(0) = CONSTL2T;
			return(0);
		case 0x1ea: /* fld2e */
			fpush();
			ST(0) = CONSTL2E;
			return(0);
		case 0x1eb: /* fldpi */
			fpush();
			ST(0) = CONSTPI;
			return(0);
		case 0x1ec: /* fldlg2 */
			fpush();
			ST(0) = CONSTLG2;
			return(0);
		case 0x1ed: /* fldln2 */
			fpush();
			ST(0) = CONSTLN2;
			return(0);
		case 0x1ee: /* fldz */
			fpush();
			ST(0) = CONSTZ;
			return(0);
		case 0x1ef:
			math_abort(info,SIGILL);
		case 0x1f0: /* f2xm1 */
		case 0x1f1: /* fyl2x */
		case 0x1f2: /* fptan */
		case 0x1f3: /* fpatan */
		case 0x1f4: /* fxtract */
		case 0x1f5: /* fprem1 */
		case 0x1f6: /* fdecstp */
		case 0x1f7: /* fincstp */
		case 0x1f8: /* fprem */
		case 0x1f9: /* fyl2xp1 */
		case 0x1fa: /* fsqrt */
		case 0x1fb: /* fsincos */
		case 0x1fe: /* fsin */
		case 0x1ff: /* fcos */
			uprintf(
			 "math_emulate: instruction %04x not implemented\n",
			  code + 0xd800);
			math_abort(info,SIGILL);
		case 0x1fc: /* frndint */
			frndint(PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0x1fd: /* fscale */
			/* incomplete and totally inadequate -wfj */
			Fscale(PST(0), PST(1), &tmp);
			real_to_real(&tmp,&ST(0));
			return(0);			/* 19 Sep 92*/
		case 0x2e9: /* ????? */
/* if this should be a fucomp ST(0),ST(1) , it must be a 0x3e9  ATS */
			fucom(PST(1),PST(0));
			fpop(); fpop();
			return(0);
		case 0x3d0: case 0x3d1: /* fist ?? */
			return(0);
		case 0x3e2: /* fclex */
			I387.swd &= 0x7f00;
			return(0);
		case 0x3e3: /* fninit */
			I387.cwd = 0x037f;
			I387.swd = 0x0000;
			I387.twd = 0x0000;
			return(0);
		case 0x3e4:
			return(0);
		case 0x6d9: /* fcompp */
			fcom(PST(1),PST(0));
			fpop(); fpop();
			return(0);
		case 0x7e0: /* fstsw ax */
			*(short *) &info->tf_eax = I387.swd;
			return(0);
	}
	switch (code >> 3) {
		case 0x18: /* fadd */
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0x19: /* fmul */
			fmul(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0x1a: /* fcom */
			fcom(PST(code & 7),PST(0));
			return(0);
		case 0x1b: /* fcomp */
			fcom(PST(code & 7),PST(0));
			fpop();
			return(0);
		case 0x1c: /* fsubr */
			real_to_real(&ST(code & 7),&tmp);
			tmp.exponent ^= 0x8000;
			fadd(PST(0),&tmp,&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0x1d: /* fsub */
			ST(0).exponent ^= 0x8000;
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0x1e: /* fdivr */
			fdiv(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0x1f: /* fdiv */
			fdiv(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0x38: /* fld */
			fpush();
			ST(0) = ST((code & 7)+1);  /* why plus 1 ????? ATS */
			return(0);
		case 0x39: /* fxch */
			fxchg(&ST(0),&ST(code & 7));
			return(0);
		case 0x3b: /*  ??? ??? wrong ???? ATS */
			ST(code & 7) = ST(0);
			fpop();
			return(0);
		case 0x98: /* fadd */
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return(0);
		case 0x99: /* fmul */
			fmul(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return(0);
		case 0x9a: /* ???? , my manual don't list a direction bit
for fcom , ??? ATS */
			fcom(PST(code & 7),PST(0));
			return(0);
		case 0x9b: /* same as above , ATS */
			fcom(PST(code & 7),PST(0));
			fpop();
			return(0);
		case 0x9c: /* fsubr */
			ST(code & 7).exponent ^= 0x8000;
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return(0);
		case 0x9d: /* fsub */
			real_to_real(&ST(0),&tmp);
			tmp.exponent ^= 0x8000;
			fadd(PST(code & 7),&tmp,&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return(0);
		case 0x9e: /* fdivr */
			fdiv(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return(0);
		case 0x9f: /* fdiv */
			fdiv(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return(0);
		case 0xb8: /* ffree */
			printf("ffree not implemented\n");
			math_abort(info,SIGILL);
		case 0xb9: /* fstp ???? where is the pop ? ATS */
			fxchg(&ST(0),&ST(code & 7));
			return(0);
		case 0xba: /* fst */
			ST(code & 7) = ST(0);
			return(0);
		case 0xbb: /* ????? encoding of fstp to mem ? ATS */
			ST(code & 7) = ST(0);
			fpop();
			return(0);
		case 0xbc: /* fucom */
			fucom(PST(code & 7),PST(0));
			return(0);
		case 0xbd: /* fucomp */
			fucom(PST(code & 7),PST(0));
			fpop();
			return(0);
		case 0xd8: /* faddp */
			fadd(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return(0);
		case 0xd9: /* fmulp */
			fmul(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return(0);
		case 0xda: /* ??? encoding of ficom with 16 bit mem ? ATS */
			fcom(PST(code & 7),PST(0));
			fpop();
			return(0);
		case 0xdc: /* fsubrp */
			ST(code & 7).exponent ^= 0x8000;
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return(0);
		case 0xdd: /* fsubp */
			real_to_real(&ST(0),&tmp);
			tmp.exponent ^= 0x8000;
			fadd(PST(code & 7),&tmp,&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return(0);
		case 0xde: /* fdivrp */
			fdiv(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return(0);
		case 0xdf: /* fdivp */
			fdiv(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return(0);
		case 0xf8: /* fild 16-bit mem ???? ATS */
			printf("ffree not implemented\n");
			math_abort(info,SIGILL);
			fpop();
			return(0);
		case 0xf9: /*  ????? ATS */
			fxchg(&ST(0),&ST(code & 7));
			return(0);
		case 0xfa: /* fist 16-bit mem ? ATS */
		case 0xfb: /* fistp 16-bit mem ? ATS */
			ST(code & 7) = ST(0);
			fpop();
			return(0);
	}
	switch ((code>>3) & 0xe7) {
		case 0x22:
			put_short_real(PST(0),info,code);
			return(0);
		case 0x23:
			put_short_real(PST(0),info,code);
			fpop();
			return(0);
		case 0x24:
			address = ea(info,code);
			for (code = 0 ; code < 7 ; code++) {
				((long *) & I387)[code] =
				   get_fs_long((unsigned long *) address);
				address += 4;
			}
			return(0);
		case 0x25:
			address = ea(info,code);
			*(unsigned short *) &I387.cwd =
				get_fs_word((unsigned short *) address);
			return(0);
		case 0x26:
			address = ea(info,code);
			/*verify_area(address,28);*/
			for (code = 0 ; code < 7 ; code++) {
				put_fs_long( ((long *) & I387)[code],
					(unsigned long *) address);
				address += 4;
			}
			return(0);
		case 0x27:
			address = ea(info,code);
			/*verify_area(address,2);*/
			put_fs_word(I387.cwd,(short *) address);
			return(0);
		case 0x62:
			put_long_int(PST(0),info,code);
			return(0);
		case 0x63:
			put_long_int(PST(0),info,code);
			fpop();
			return(0);
		case 0x65:
			fpush();
			get_temp_real(&tmp,info,code);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0x67:
			put_temp_real(PST(0),info,code);
			fpop();
			return(0);
		case 0xa2:
			put_long_real(PST(0),info,code);
			return(0);
		case 0xa3:
			put_long_real(PST(0),info,code);
			fpop();
			return(0);
		case 0xa4:
			address = ea(info,code);
			for (code = 0 ; code < 27 ; code++) {
				((long *) & I387)[code] =
				   get_fs_long((unsigned long *) address);
				address += 4;
			}
			return(0);
		case 0xa6:
			address = ea(info,code);
			/*verify_area(address,108);*/
			for (code = 0 ; code < 27 ; code++) {
				put_fs_long( ((long *) & I387)[code],
					(unsigned long *) address);
				address += 4;
			}
			I387.cwd = 0x037f;
			I387.swd = 0x0000;
			I387.twd = 0x0000;
			return(0);
		case 0xa7:
			address = ea(info,code);
			/*verify_area(address,2);*/
			put_fs_word(I387.swd,(short *) address);
			return(0);
		case 0xe2:
			put_short_int(PST(0),info,code);
			return(0);
		case 0xe3:
			put_short_int(PST(0),info,code);
			fpop();
			return(0);
		case 0xe4:
			fpush();
			get_BCD(&tmp,info,code);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0xe5:
			fpush();
			get_longlong_int(&tmp,info,code);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 0xe6:
			put_BCD(PST(0),info,code);
			fpop();
			return(0);
		case 0xe7:
			put_longlong_int(PST(0),info,code);
			fpop();
			return(0);
	}
	switch (code >> 9) {
		case 0:
			get_short_real(&tmp,info,code);
			break;
		case 1:
			get_long_int(&tmp,info,code);
			break;
		case 2:
			get_long_real(&tmp,info,code);
			break;
		case 4:
			get_short_int(&tmp,info,code);
	}
	switch ((code>>3) & 0x27) {
		case 0:
			fadd(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 1:
			fmul(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 2:
			fcom(&tmp,PST(0));
			return(0);
		case 3:
			fcom(&tmp,PST(0));
			fpop();
			return(0);
		case 4:
			tmp.exponent ^= 0x8000;
			fadd(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 5:
			ST(0).exponent ^= 0x8000;
			fadd(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 6:
			fdiv(PST(0),&tmp,&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
		case 7:
			fdiv(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return(0);
	}
	if ((code & 0x138) == 0x100) {
			fpush();
			real_to_real(&tmp,&ST(0));
			return(0);
	}
	printf("Unknown math-insns: %04x:%08x %04x\n",(u_short)info->tf_cs,
		info->tf_eip,code);
	math_abort(info,SIGFPE);
}
예제 #14
0
static void square_move(board_t * board, int from, int to, int piece, bool update) {

   int colour;
   int pos;
   int from_64, to_64;
   int piece_12;
   int piece_index;
   uint64 hash_xor;

   ASSERT(board!=NULL);
   ASSERT(SQUARE_IS_OK(from));
   ASSERT(SQUARE_IS_OK(to));
   ASSERT(piece_is_ok(piece));
   ASSERT(update==true||update==false);

   // init

   colour = PIECE_COLOUR(piece);

   pos = board->pos[from];
   ASSERT(pos>=0);

   // from

   ASSERT(board->square[from]==piece);
   board->square[from] = Empty;

   ASSERT(board->pos[from]==pos);
   board->pos[from] = -1; // not needed

   // to

   ASSERT(board->square[to]==Empty);
   board->square[to] = piece;

   ASSERT(board->pos[to]==-1);
   board->pos[to] = pos;

   // piece list

   if (!PIECE_IS_PAWN(piece)) {

      ASSERT(board->piece[colour][pos]==from);
      board->piece[colour][pos] = to;

   } else {

      ASSERT(board->pawn[colour][pos]==from);
      board->pawn[colour][pos] = to;

      // pawn "bitboard"

      board->pawn_file[colour][SQUARE_FILE(from)] ^= BIT(PAWN_RANK(from,colour));
      board->pawn_file[colour][SQUARE_FILE(to)]   ^= BIT(PAWN_RANK(to,colour));
   }

   // update

   if (update) {

      // init

      from_64 = SQUARE_TO_64(from);
      to_64 = SQUARE_TO_64(to);
      piece_12 = PIECE_TO_12(piece);

      // PST

      board->opening += PST(piece_12,to_64,Opening) - PST(piece_12,from_64,Opening);
      board->endgame += PST(piece_12,to_64,Endgame) - PST(piece_12,from_64,Endgame);

      // hash key

      piece_index = RandomPiece + (piece_12^1) * 64; // HACK: ^1 for PolyGlot book

      hash_xor = RANDOM_64(piece_index+to_64) ^ RANDOM_64(piece_index+from_64);

      board->key ^= hash_xor;
      if (PIECE_IS_PAWN(piece)) board->pawn_key ^= hash_xor;
   }
}
예제 #15
0
static void square_set(board_t * board, int square, int piece, int pos, bool update) {

   int piece_12, colour;
   int sq;
   int i, size;
   int sq_64;
   uint64 hash_xor;

   ASSERT(board!=NULL);
   ASSERT(SQUARE_IS_OK(square));
   ASSERT(piece_is_ok(piece));
   ASSERT(pos>=0);
   ASSERT(update==true||update==false);

   // init

   piece_12 = PIECE_TO_12(piece);
   colour = PIECE_COLOUR(piece);

   // square

   ASSERT(board->square[square]==Empty);
   board->square[square] = piece;

   // piece list

   if (!PIECE_IS_PAWN(piece)) {

      // init

      size = board->piece_size[colour];
      ASSERT(size>=0);

      // size

      size++;

      board->piece[colour][size] = SquareNone;
      board->piece_size[colour] = size;

      // stable swap

      ASSERT(pos>=0&&pos<size);

      for (i = size-1; i > pos; i--) {

         sq = board->piece[colour][i-1];

         board->piece[colour][i] = sq;

         ASSERT(board->pos[sq]==i-1);
         board->pos[sq] = i;
      }

      board->piece[colour][pos] = square;

      ASSERT(board->pos[square]==-1);
      board->pos[square] = pos;

   } else {

      // init

      size = board->pawn_size[colour];
      ASSERT(size>=0);

      // size

      size++;

      board->pawn[colour][size] = SquareNone;
      board->pawn_size[colour] = size;

      // stable swap

      ASSERT(pos>=0&&pos<size);

      for (i = size-1; i > pos; i--) {

         sq = board->pawn[colour][i-1];

         board->pawn[colour][i] = sq;

         ASSERT(board->pos[sq]==i-1);
         board->pos[sq] = i;
      }

      board->pawn[colour][pos] = square;

      ASSERT(board->pos[square]==-1);
      board->pos[square] = pos;

      // pawn "bitboard"

      board->pawn_file[colour][SQUARE_FILE(square)] ^= BIT(PAWN_RANK(square,colour));
   }

   // material

   ASSERT(board->piece_nb<32);
   board->piece_nb++;;

   ASSERT(board->number[piece_12]<9);
   board->number[piece_12]++;

   // update

   if (update) {

      // init

      sq_64 = SQUARE_TO_64(square);

      // PST

      board->opening += PST(piece_12,sq_64,Opening);
      board->endgame += PST(piece_12,sq_64,Endgame);

      // hash key

      hash_xor = RANDOM_64(RandomPiece+(piece_12^1)*64+sq_64); // HACK: ^1 for PolyGlot book

      board->key ^= hash_xor;
      if (PIECE_IS_PAWN(piece)) board->pawn_key ^= hash_xor;

      // material key

      board->material_key ^= RANDOM_64(piece_12*16+(board->number[piece_12]-1));
   }
}
예제 #16
0
static void square_clear(board_t * board, int square, int piece, bool update) {

   int pos, piece_12, colour;
   int sq;
   int i, size;
   int sq_64;
   uint64 hash_xor;

   ASSERT(board!=NULL);
   ASSERT(SQUARE_IS_OK(square));
   ASSERT(piece_is_ok(piece));
   ASSERT(update==true||update==false);

   // init

   pos = board->pos[square];
   ASSERT(pos>=0);

   piece_12 = PIECE_TO_12(piece);
   colour = PIECE_COLOUR(piece);

   // square

   ASSERT(board->square[square]==piece);
   board->square[square] = Empty;

   // piece list

   if (!PIECE_IS_PAWN(piece)) {

      // init

      size = board->piece_size[colour];
      ASSERT(size>=1);

      // stable swap

      ASSERT(pos>=0&&pos<size);

      ASSERT(board->pos[square]==pos);
      board->pos[square] = -1;

      for (i = pos; i < size-1; i++) {

         sq = board->piece[colour][i+1];

         board->piece[colour][i] = sq;

         ASSERT(board->pos[sq]==i+1);
         board->pos[sq] = i;
      }

      // size

      size--;

      board->piece[colour][size] = SquareNone;
      board->piece_size[colour] = size;

   } else {

      // init

      size = board->pawn_size[colour];
      ASSERT(size>=1);

      // stable swap

      ASSERT(pos>=0&&pos<size);

      ASSERT(board->pos[square]==pos);
      board->pos[square] = -1;

      for (i = pos; i < size-1; i++) {

         sq = board->pawn[colour][i+1];

         board->pawn[colour][i] = sq;

         ASSERT(board->pos[sq]==i+1);
         board->pos[sq] = i;
      }

      // size

      size--;

      board->pawn[colour][size] = SquareNone;
      board->pawn_size[colour] = size;

      // pawn "bitboard"

      board->pawn_file[colour][SQUARE_FILE(square)] ^= BIT(PAWN_RANK(square,colour));
   }

   // material

   ASSERT(board->piece_nb>0);
   board->piece_nb--;

   ASSERT(board->number[piece_12]>0);
   board->number[piece_12]--;

   board->piece_material[colour] -= VALUE_PIECE(piece);  // Thomas 
   
   // update

   if (update) {

      // init

      sq_64 = SQUARE_TO_64(square);

      // PST

      board->opening -= PST(piece_12,sq_64,Opening);
      board->endgame -= PST(piece_12,sq_64,Endgame);

      // hash key

      hash_xor = RANDOM_64(RandomPiece+(piece_12^1)*64+sq_64); // HACK: ^1 for PolyGlot book

      board->key ^= hash_xor;
      if (PIECE_IS_PAWN(piece)) board->pawn_key ^= hash_xor;

      // material key

      board->material_key ^= RANDOM_64(piece_12*16+board->number[piece_12]);
   }
}
예제 #17
0
파일: make_move.c 프로젝트: Censor/Ivanhoe
void MakeWhite (typePOS* POSITION, uint32 move)
{
  int fr, to, pi, fl, cp, z;
  uint64 mask;
  TRACE (TRACE_MAKE_UNMAKE,
	 printf ("Mw %d %s\n", HEIGHT (POSITION), Notate(move, STRING1[POSITION->cpu])));
  POSITION->nodes++;
  if (!TITANIC_MODE) /* new */
    {
      NODE_CHECK++;
      if ((NODE_CHECK & 4095) == 0)
	CheckDone (POSITION, 0);
    }
  memcpy (POSITION->DYN + 1, POSITION->DYN, 32);
  fr = FROM (move);
  to = TO (move);
#ifdef CHESS_960
  if (UCI_OPTION_CHESS_960 && MoveIsOO (move))
    {
      Castle960White (POSITION, move, to, fr);
      return;
    }
#endif
  pi = POSITION->sq[fr];
  POSITION->DYN++;
  REV_HASH (POSITION);
  POSITION->DYN->reversible++;
  POSITION->DYN->move = move;
  fl = CastleTable[fr] & CastleTable[to] & POSITION->DYN->oo;
  POSITION->DYN->HASH ^= ZobristCastling[POSITION->DYN->oo ^ fl];
  POSITION->DYN->PAWN_HASH ^= ZobristCastling[POSITION->DYN->oo ^ fl];
  POSITION->DYN->oo = fl;
  if (POSITION->DYN->ep)
    {
      POSITION->DYN->HASH ^= ZobristEP[POSITION->DYN->ep & 7];
      POSITION->DYN->ep = 0;
    }
  POSITION->sq[fr] = 0;
  mask = SqClear[fr];
  wBitboardOcc &= mask;
  POSITION->bitboard[pi] &= mask;
  ClearOccupied (mask, fr);
  POSITION->DYN->STATIC += PST (pi, to) - PST (pi, fr);
  mask = Zobrist (pi, fr) ^ Zobrist (pi, to);
  cp = POSITION->sq[to];
  POSITION->DYN->cp = cp;
  POSITION->DYN->HASH ^= mask;
  if (pi == wEnumP)
    POSITION->DYN->PAWN_HASH ^= mask;
  POSITION->wtm ^= 1;
  POSITION->height++;
  POSITION->DYN->HASH ^= ZobristWTM;
  if (pi == wEnumK)
    {
      POSITION->DYN->PAWN_HASH ^= mask;
      POSITION->wKsq = to;
    }
  if (cp)
    {
      mask = SqClear[to];
      bBitboardOcc &= mask;
      POSITION->bitboard[cp] &= mask;
      POSITION->DYN->material -= MATERIAL_VALUE[cp];
      POSITION->DYN->STATIC -= PST (cp, to);
      if (cp == bEnumP)
	POSITION->DYN->PAWN_HASH ^= Zobrist (cp, to);
      POSITION->DYN->HASH ^= Zobrist (cp, to);
      POSITION->DYN->reversible = 0;
    }
  else
    {
      mask = SqSet[to];
      SetOccupied (mask, to);
      if (MoveIsOO (move))
	{
	  REV_CASTLE (POSITION);
	  MakeWhiteOO (POSITION, to);
	}
    }
  POSITION->sq[to] = pi;
  wBitboardOcc |= SqSet[to];
  POSITION->bitboard[pi] |= SqSet[to];
  if (pi == wEnumP)
    {
      POSITION->DYN->reversible = 0;
      if (MoveIsEP (move))
	{
	  z = to ^ 8;
	  mask = SqClear[z];
	  bBitboardOcc &= mask;
	  bBitboardP &= mask;
	  ClearOccupied (mask, z);
	  POSITION->DYN->material -= MATERIAL_VALUE[bEnumP];
	  POSITION->DYN->STATIC -= PST (bEnumP, z);
	  POSITION->DYN->HASH ^= Zobrist (bEnumP, z);
	  POSITION->DYN->PAWN_HASH ^= Zobrist (bEnumP, z);
	  POSITION->sq[z] = 0;
	}
      else if (MoveIsProm (move))
	{
	  pi = PromW[(move & FLAG_MASK) >> 12];
	  if (pi == wEnumBL && SqSet[to] & DARK)
	    pi = wEnumBD;
	  POSITION->sq[to] = pi;
	  if (POSITION->bitboard[pi])
	    POSITION->DYN->material |= 0x80000000;
	  wBitboardP &= SqClear[to];
	  POSITION->bitboard[pi] |= SqSet[to];
	  POSITION->DYN->material += MATERIAL_VALUE[pi] - MATERIAL_VALUE[wEnumP];
	  POSITION->DYN->STATIC += PST (pi, to) - PST (wEnumP, to);
	  POSITION->DYN->HASH ^= Zobrist (pi, to) ^ Zobrist (wEnumP, to);
	  POSITION->DYN->PAWN_HASH ^= Zobrist (wEnumP, to);
	}
      else if ((to ^ fr) == 16)
예제 #18
0
void MakeWhite( typePos* Position, uint32 move )
    {
    int fr, to, pi, fl, cp, z;
    uint64 mask;
   Position->nodes++;
    memcpy(Position->Dyn + 1, Position->Dyn, 32);
    fr = From(move);
    to = To(move);

#ifdef FischerRandom
    if (Chess960 && MoveIsOO(move))
        {
        Castle960White(Position, move, to, fr);
        return;
        }
#endif

    pi = Position->sq[fr];
    Position->Dyn++;
    Position->Dyn->reversible++;
    Position->Dyn->move = move;
    fl = CastleTable[fr] & CastleTable[to] & Position->Dyn->oo;
    Position->Dyn->Hash ^= HashCastling[Position->Dyn->oo ^ fl];
    Position->Dyn->PawnHash ^= HashCastling[Position->Dyn->oo ^ fl];
    Position->Dyn->oo = fl;
    if (Position->Dyn->ep)
        {
        Position->Dyn->Hash ^= HashEP[Position->Dyn->ep & 7];
        Position->Dyn->ep = 0;
        }
    Position->sq[fr] = 0;
    mask = SqClear[fr];
    wBitboardOcc &= mask;
    Position->bitboard[pi] &= mask;
    ClearOccupied(mask, fr);
    Position->Dyn->Static += PST(pi, to) - PST(pi, fr);
    mask = Hash(pi, fr) ^ Hash(pi, to);
    cp = Position->sq[to];
    Position->Dyn->cp = cp;
    Position->Dyn->Hash ^= mask;
    if (pi == wEnumP)
        Position->Dyn->PawnHash ^= mask;
    Position->wtm ^= 1;
    Position->height++;
	UpdateSeldepth(Position);
    Position->Dyn->Hash ^= HashWTM;
    if (pi == wEnumK)
        {
        Position->Dyn->PawnHash ^= mask;
        Position->wKsq = to;
        }
    if (cp)
        {
        mask = SqClear[to];
        bBitboardOcc &= mask;
        Position->bitboard[cp] &= mask;
        Position->Dyn->material -= MaterialValue[cp];
        Position->Dyn->Static -= PST(cp, to);
        if (cp == bEnumP)
            Position->Dyn->PawnHash ^= Hash(cp, to);
        Position->Dyn->Hash ^= Hash(cp, to);
        Position->Dyn->reversible = 0;
        }
    else
        {
        mask = SqSet[to];
        SetOccupied(mask, to);
        if (MoveIsOO(move))
            {
            RevCastle(Position);
            MakeWhiteOO(Position, to);
            }
        }
    Position->sq[to] = pi;
    wBitboardOcc |= SqSet[to];
    Position->bitboard[pi] |= SqSet[to];
    if (pi == wEnumP)
        {
        Position->Dyn->reversible = 0;
        if (MoveIsEP(move))
            {
            z = to ^ 8;
            mask = SqClear[z];
            bBitboardOcc &= mask;
            bBitboardP &= mask;
            ClearOccupied(mask, z);
            Position->Dyn->material -= MaterialValue[bEnumP];
            Position->Dyn->Static -= PST(bEnumP, z);
            Position->Dyn->Hash ^= Hash(bEnumP, z);
            Position->Dyn->PawnHash ^= Hash(bEnumP, z);
            Position->sq[z] = 0;
            }
        else if (MoveIsProm(move))
            {
            pi = PromW[(move & FlagMask) >> 12];
            if (pi == wEnumBL && SqSet[to] & Black)
                pi = wEnumBD;
            Position->sq[to] = pi;
            if (Position->bitboard[pi])
               Position->Dyn->material |= 0x80000000;
            wBitboardP &= SqClear[to];
            Position->bitboard[pi] |= SqSet[to];
            Position->Dyn->material += MaterialValue[pi] - MaterialValue[wEnumP];
            Position->Dyn->Static += PST(pi, to) - PST(wEnumP, to);
            Position->Dyn->Hash ^= Hash(pi, to) ^ Hash(wEnumP, to);
            Position->Dyn->PawnHash ^= Hash(wEnumP, to);
            }
        else if ((to ^ fr) == 16)