コード例 #1
0
ファイル: rotation.cpp プロジェクト: madaan/entire-src
void shift(int A[MAX], int units) {
    if(units < 0) {
        left_shift(A, -units);
    } else if(units > 0) {
        right_shift(A, units);
    }
}
コード例 #2
0
ファイル: huge.c プロジェクト: ketan936/college-work
/**
 * dividend = numerator, divisor = denominator
 *
 * Note that this process destroys divisor (and, of course,
 * overwrites quotient). The dividend is the remainder of the 
 * division (if that's important to the caller). The divisor will 
 * be modified by this routine, but it will end up back where it
 * “started”.
 */
void divide( huge *dividend, huge *divisor, huge *quotient )
{
  int bit_size, bit_position;

  // "bit_position" keeps track of which bit, of the quotient, 
  // is being set or cleared on the current operation.
  bit_size = bit_position = 0;

  // First, left-shift divisor until it's >= than the dividend
  while ( compare( divisor, dividend ) < 0 )
  {
    left_shift( divisor );
    bit_size++;
  }

  // overestimates a bit in some cases
  if ( quotient )
  {
    quotient->sign = !( dividend->sign == dividend->sign );
    quotient->size = ( bit_size / 8 ) + 1;
    quotient->rep = ( unsigned char * ) 
      calloc(quotient->size, sizeof( unsigned char ) );
    memset( quotient->rep, 0, quotient->size );
  }
  
  bit_position = 8 - ( bit_size % 8 ) - 1;

  do
  {
    if ( compare( divisor, dividend ) <= 0 )
    {
      subtract_magnitude( dividend, divisor );  // dividend -= divisor
      if ( quotient )
      {
        quotient->rep[ ( int ) ( bit_position / 8 ) ] |=
          ( 0x80 >> ( bit_position % 8 ) );
      }
    }

    if ( bit_size )
    {
      right_shift( divisor );
    }
    bit_position++;
  }
コード例 #3
0
ファイル: Jet.c プロジェクト: jonathan84clark/JConsole5
/**************************************************************
* MOVE UP
**************************************************************/
char jet_moveUp(struct Jet* input)
{
   if (input -> yLocation == 0 && input -> yPos == 8)
   {
      return 1;
   }
   else
   {
	  char move_index;
      if (input -> yPos == 8)
      {
         set_LCD_Cursor(input -> xLocation, input -> yLocation + 1);
    	 for (move_index = 0; move_index < JET_LENGTH; move_index++)
    	 {
    		 LcdWrite(0x00);
    		 input -> bot_row[move_index] = input -> mid_row[move_index];
    		 input -> mid_row[move_index] = input -> top_row[move_index];
    		 input -> top_row[move_index] = 0x00;
    	 }
         input -> yPos = 0;
         input -> yLocation--;
      }
      //Shift the object values to make it appear to move up
      for (move_index = 0; move_index < JET_LENGTH; move_index++)
      {
    	  right_shift(&input -> mid_row[move_index], &input -> top_row[move_index]);
    	  if ((input -> bot_row[move_index] & 0x01) == 0x01)
    	  {
    		  input -> mid_row[move_index] = input -> mid_row[move_index] | 0x80;
    	  }
    	  input -> bot_row[move_index] = input -> bot_row[move_index] >> 1;
      }
      input -> yPos++;
      input -> yPixelPosition--;
      display_jet(input, 0);
      return 0;
   }
}
コード例 #4
0
ファイル: Falcon.c プロジェクト: jonathan84clark/JConsole5
/****************************************************
* Falcon MOVE UP
****************************************************/
char Falcon_moveUp(struct Falcon* Falcon)
{
   if (Falcon -> yPixelPosition == 0)
   {
      return 1;
   }
   else
   {
	  char falcon_index;
      if (Falcon -> yPos == 8)
      {
         set_LCD_Cursor(Falcon -> xLocation, Falcon -> yLocation + 1);
	     for (falcon_index = 0; falcon_index < SHIP_LENGTH; falcon_index++)
	     {
	        LcdWrite(0x00);
	        Falcon -> bot_row[falcon_index] = Falcon -> mid_row[falcon_index];
	        Falcon -> mid_row[falcon_index] = Falcon -> top_row[falcon_index];
	        Falcon -> top_row[falcon_index] = 0x00;
	     }
	     Falcon -> yPos = 0;
	     Falcon -> yLocation--;
	  }
	  //Shift the object values to make it appear to move up
	  for (falcon_index = 0; falcon_index < SHIP_LENGTH; falcon_index++)
	  {
		 right_shift(&Falcon -> mid_row[falcon_index], &Falcon -> top_row[falcon_index]);
	     if ((Falcon -> bot_row[falcon_index] & 0x01) == 0x01)
	     {
	        Falcon -> mid_row[falcon_index] = Falcon -> mid_row[falcon_index] | 0x80;
	     }
	     Falcon -> bot_row[falcon_index] = Falcon -> bot_row[falcon_index] >> 1;
      }
	  Falcon -> yPos++;
	  Falcon -> yPixelPosition--;
	  displayFalcon(Falcon, 0);
	  return 0;
   }
}
コード例 #5
0
ファイル: codegen14.c プロジェクト: jdelgadoalfonso/gputils
static void
do_rsh(enum size_tag size, gp_boolean is_const, int value, char *name)
{
  int i;
  gp_boolean is_signed = false;
  char *reg1 = NULL;
  char *reg2 = NULL;
  char *label1 = NULL;
  char *label2 = NULL;

  switch (size) {
  case size_bit:
    assert(0);
    break;
  case size_int8:
    is_signed = true;
    /* fall through */
  case size_uint8:
    reg1 = codegen_get_temp(size);
    if (is_const) {
      codegen_write_asm("movwf %s", reg1);
      for (i = 0; i < value; i++) {
        if (is_signed) {
          /* put the sign in the carry */
          codegen_write_asm("rlf %s, w", reg1);
        } else {
          codegen_write_asm("bcf STATUS, C");
        }
        codegen_write_asm("rrf %s, f", reg1, i);    
      }
      codegen_write_asm("movf %s, w", reg1);  /* move the result into w */
    } else {
      reg2 = codegen_get_temp(size);
      label1 = codegen_next_label();
      label2 = codegen_next_label();

      codegen_write_asm("movwf %s", reg1);
      codegen_write_asm("movf %s, w", name);
      codegen_write_asm("movwf %s", reg2);
      codegen_write_label(label1);
      codegen_write_asm("btfsc STATUS, Z");
      codegen_write_asm("goto %s", label2);
      if (is_signed) {
        /* put the sign in the carry */
        codegen_write_asm("rlf %s, w", reg1);
      } else {
        codegen_write_asm("bcf STATUS, C");
      }
      codegen_write_asm("rrf %s, f", reg1);
      codegen_write_asm("decf %s, f", reg2);
      codegen_write_asm("goto %s", label1);
      codegen_write_label(label2);
      codegen_write_asm("movf %s, w", reg1);  /* move the result into w */
    }
    break;
  case size_int16:
  case size_int24:
  case size_int32:
    is_signed = true;
    /* fall through */
  case size_uint16:
  case size_uint24:
  case size_uint32:
    reg1 = codegen_get_temp(size_uint8);
    label1 = codegen_next_label();
    label2 = codegen_next_label();
    if (is_const) {
      codegen_write_asm("movlw %#x", value);
      codegen_write_asm("addlw 0", value);
    } else {
      /* never can shift more than 31 so read the bottom byte only */
      codegen_write_asm("movf %s, w", name);
    }
    codegen_write_asm("movwf %s", reg1);
    codegen_write_label(label1);
    codegen_write_asm("btfsc STATUS, Z");
    codegen_write_asm("goto %s", label2);
    codegen_write_asm("bcf STATUS, C");
    right_shift(size, is_signed);
    codegen_write_asm("decf %s, f", reg1);
    codegen_write_asm("goto %s", label1);
    codegen_write_label(label2);
    break;
  case size_float:
  default:
    assert(0);
  }

  if (reg1)
    free(reg1);

  if (reg2)
    free(reg2);

  if (label1)
    free(label1);

  if (label2)
    free(label2);

}
コード例 #6
0
//==================================================================
static PFORCEINLINE int div2( int val )
{
	return right_shift( val, 1 );
}
コード例 #7
0
static void blockToHaar( const TBLOCK *in_blockp,
						 short out_haarp[ScreenHaarComprPack::BLOCK_DIM][ScreenHaarComprPack::BLOCK_DIM],
						 u_int block_dim,
						 u_int min_dim,
						 u_int shift_bits )
{
	PASSERT( min_dim >= 2 );

	TMPTYPE tmp_line1[ScreenHaarComprPack::BLOCK_DIM];
	TMPTYPE tmp_line2[ScreenHaarComprPack::BLOCK_DIM];
	TMPTYPE tmp_haar[ScreenHaarComprPack::BLOCK_DIM][ScreenHaarComprPack::BLOCK_DIM];

#if 0
	for (int y=0; y < block_dim; ++y)
	{
		for (int x=0; x < block_dim; ++x)
		{
			*out_haarp++ = *in_blockp++;
		}
	}
	return;
#endif

	for (int y=0; y < block_dim; ++y)
	{
		int	y_off = y * block_dim;

		for (int i=0; i < block_dim; ++i)
			tmp_line1[i] = in_blockp[ i + y_off ];

		for (int n = block_dim; n >= min_dim; n /= 2)
		{
			for (int i=0; i < n; ++i)
				tmp_line2[i] = tmp_line1[i];

			makeAvgAndDiff( tmp_line2, tmp_line1, n );
		}

		for (int i=0; i < block_dim; ++i)
			tmp_haar[i][y] = tmp_line1[i];
	}

	for (int x=0; x < block_dim; ++x)
	{
		//for (int i=0; i < block_dim; ++i)
		//	tmp_line1[i] = tmp_haar[x][i];
		memcpy( tmp_line1, tmp_haar[x], ScreenHaarComprPack::BLOCK_DIM*sizeof(tmp_line1[0]) );

		for (int n = block_dim; n >= min_dim; n /= 2)
		{
			for (int i=0; i < n; ++i)
				tmp_line2[i] = tmp_line1[i];

			makeAvgAndDiff( tmp_line2, tmp_line1, n );
		}

		for (int i=0; i < block_dim; ++i)
		{
			//if ( x == 0 && i == 0 )
			//	out_haarp[x][i] = pack_sign( tmp_line1[i] );
			//else
				out_haarp[x][i] = pack_sign( right_shift( tmp_line1[i], shift_bits ) );
		}
	}
}