Exemplo n.º 1
0
int JComplexData::compareTo(const JObject& s) const {
  if (className() != s.className())
    return JObject::compareTo(s);
  return cmp(value.norm(), ((JComplexData*)&s)->value.norm());
}
Exemplo n.º 2
0
/* Сравнение 2-х строк
 * s > p  |  1
 * s = p  |  0
 * s < p  |  -1   */
int cmp(char *s, char *p)
{
	return *s ? *p ? *s == *p ? cmp(++s, ++p) : *s > *p ? 1 : -1 : 1 : *p ? -1 : 0; // 53
}
Exemplo n.º 3
0
int CollateJSON(const sized_buf *buf1,
                const sized_buf *buf2,
                CollateJSONMode mode)
{
    const char* str1 = buf1->buf;
    const char* str2 = buf2->buf;
    int depth = 0;

    do {
        /* Get the types of the next token in each string: */
        ValueType type1 = valueTypeOf(*str1);
        ValueType type2 = valueTypeOf(*str2);
        /* If types don't match, stop and return their relative ordering: */
        if (type1 != type2) {
            if (mode != kCollateJSON_Raw)
                return cmp(type1, type2);
            else
                return cmp(kRawOrderOfValueType[type1], kRawOrderOfValueType[type2]);

        /* If types match, compare the actual token values: */
        } else switch (type1) {
            case kNull:
            case kTrue:
                str1 += 4;
                str2 += 4;
                break;
            case kFalse:
                str1 += 5;
                str2 += 5;
                break;
            case kNumber: {
                char* next1, *next2;
                int diff;
                if (depth == 0) {
                    /* At depth 0, be careful not to fall off the end of the
                       input, because there won't be any delimiters (']' or
                       '}') after the number! */
                    diff = dcmp( readNumber(str1, buf1->buf + buf1->size, &next1),
                                 readNumber(str2, buf2->buf + buf2->size, &next2) );
                } else {
                    diff = dcmp( strtod(str1, &next1), strtod(str2, &next2) );
                }
                if (diff)
                    return diff; /* Numbers don't match */
                str1 = next1;
                str2 = next2;
                break;
            }
            case kString: {
                int diff;
                if (mode == kCollateJSON_Unicode)
                    diff = compareStringsUnicode(&str1, &str2);
                else
                    diff = compareStringsASCII(&str1, &str2);
                if (diff)
                    return diff; /* Strings don't match */
                break;
            }
            case kArray:
            case kObject:
                ++str1;
                ++str2;
                ++depth;
                break;
            case kEndArray:
            case kEndObject:
                ++str1;
                ++str2;
                --depth;
                break;
            case kComma:
            case kColon:
                ++str1;
                ++str2;
                break;
            case kIllegal:
                return 0;
        }
    /* Keep going as long as we're inside an array or object */
    } while (depth > 0);
    return 0;
}
Exemplo n.º 4
0
	void compile(RuntimeBlockInfo* block, bool force_checks, bool reset, bool staging, bool optimise) {
		mov(rax, (size_t)&cycle_counter);

		sub(dword[rax], block->guest_cycles);

		sub(rsp, 0x28);

		for (size_t i = 0; i < block->oplist.size(); i++) {
			shil_opcode& op  = block->oplist[i];
			switch (op.op) {

			case shop_ifb:
				if (op.rs1._imm)
				{
					mov(rax, (size_t)&next_pc);
					mov(dword[rax], op.rs2._imm);
				}

				mov(call_regs[0], op.rs3._imm);

				call((void*)OpDesc[op.rs3._imm]->oph);
				break;

			case shop_jcond:
			case shop_jdyn:
				{
					mov(rax, (size_t)op.rs1.reg_ptr());

					mov(ecx, dword[rax]);

					if (op.rs2.is_imm()) {
						add(ecx, op.rs2._imm);
					}

					mov(rdx, (size_t)op.rd.reg_ptr());
					mov(dword[rdx], ecx);
				}
				break;

			case shop_mov32:
			{
				verify(op.rd.is_reg());

				verify(op.rs1.is_reg() || op.rs1.is_imm());

				sh_to_reg(op.rs1, mov, ecx);

				reg_to_sh(op.rd, ecx);
			}
			break;

			case shop_mov64:
			{
				verify(op.rd.is_reg());

				verify(op.rs1.is_reg() || op.rs1.is_imm());

				sh_to_reg(op.rs1, mov, rcx);

				reg_to_sh(op.rd, rcx);
			}
			break;

			case shop_readm:
			{
				sh_to_reg(op.rs1, mov, call_regs[0]);
				sh_to_reg(op.rs3, add, call_regs[0]);

				u32 size = op.flags & 0x7f;

				if (size == 1) {
					call((void*)ReadMem8);
					movsx(rcx, al);
				}
				else if (size == 2) {
					call((void*)ReadMem16);
					movsx(rcx, ax);
				}
				else if (size == 4) {
					call((void*)ReadMem32);
					mov(rcx, rax);
				}
				else if (size == 8) {
					call((void*)ReadMem64);
					mov(rcx, rax);
				}
				else {
					die("1..8 bytes");
				}

				if (size != 8)
					reg_to_sh(op.rd, ecx);
				else
					reg_to_sh(op.rd, rcx);
			}
			break;

			case shop_writem:
			{
				u32 size = op.flags & 0x7f;
				sh_to_reg(op.rs1, mov, call_regs[0]);
				sh_to_reg(op.rs3, add, call_regs[0]);

				if (size != 8)
					sh_to_reg(op.rs2, mov, call_regs[1]);
				else
					sh_to_reg(op.rs2, mov, call_regs64[1]);

				if (size == 1)
					call((void*)WriteMem8);
				else if (size == 2)
					call((void*)WriteMem16);
				else if (size == 4)
					call((void*)WriteMem32);
				else if (size == 8)
					call((void*)WriteMem64);
				else {
					die("1..8 bytes");
				}
			}
			break;

			default:
				shil_chf[op.op](&op);
				break;
			}
		}

		mov(rax, (size_t)&next_pc);

		switch (block->BlockType) {

		case BET_StaticJump:
		case BET_StaticCall:
			//next_pc = block->BranchBlock;
			mov(dword[rax], block->BranchBlock);
			break;

		case BET_Cond_0:
		case BET_Cond_1:
			{
				//next_pc = next_pc_value;
				//if (*jdyn == 0)
				//next_pc = branch_pc_value;

				mov(dword[rax], block->NextBlock);

				if (block->has_jcond)
					mov(rdx, (size_t)&Sh4cntx.jdyn);
				else
					mov(rdx, (size_t)&sr.T);

				cmp(dword[rdx], block->BlockType & 1);
				Xbyak::Label branch_not_taken;

				jne(branch_not_taken, T_SHORT);
				mov(dword[rax], block->BranchBlock);
				L(branch_not_taken);
			}
			break;

		case BET_DynamicJump:
		case BET_DynamicCall:
		case BET_DynamicRet:
			//next_pc = *jdyn;
			mov(rdx, (size_t)&Sh4cntx.jdyn);
			mov(edx, dword[rdx]);
			mov(dword[rax], edx);
			break;

		case BET_DynamicIntr:
		case BET_StaticIntr:
			if (block->BlockType == BET_DynamicIntr) {
				//next_pc = *jdyn;
				mov(rdx, (size_t)&Sh4cntx.jdyn);
				mov(edx, dword[rdx]);
				mov(dword[rax], edx);
			}
			else {
				//next_pc = next_pc_value;
				mov(dword[rax], block->NextBlock);
			}

			call((void*)UpdateINTC);
			break;

		default:
			die("Invalid block end type");
		}


		add(rsp, 0x28);
		ret();

		ready();

		block->code = (DynarecCodeEntryPtr)getCode();

		emit_Skip(getSize());
	}
Exemplo n.º 5
0
 void c_read(uint32_t v, unsigned char *buf, size_t len, off_t off)
 {
     memset(buf, 0xFF, len);
     read(buf, len, off);
     cmp(v, buf, len);
 }
Exemplo n.º 6
0
static void
slurp(INPUT *F)
{
	LINE *lp, *lastlp, tmp;
	size_t len;
	int cnt;
	char *bp, *fieldp;

	/*
	 * Read all of the lines from an input file that have the same
	 * join field.
	 */
	F->setcnt = 0;
	for (lastlp = NULL;; ++F->setcnt) {
		/*
		 * If we're out of space to hold line structures, allocate
		 * more.  Initialize the structure so that we know that this
		 * is new space.
		 */
		if (F->setcnt == F->setalloc) {
			cnt = F->setalloc;
			F->setalloc += 50;
			if ((F->set = realloc(F->set,
			    F->setalloc * sizeof(LINE))) == NULL)
				err(1, NULL);
			memset(F->set + cnt, 0, 50 * sizeof(LINE));

			/* re-set lastlp in case it moved */
			if (lastlp != NULL)
				lastlp = &F->set[F->setcnt - 1];
		}

		/*
		 * Get any pushed back line, else get the next line.  Allocate
		 * space as necessary.  If taking the line from the stack swap
		 * the two structures so that we don't lose space allocated to
		 * either structure.  This could be avoided by doing another
		 * level of indirection, but it's probably okay as is.
		 */
		lp = &F->set[F->setcnt];
		if (F->setcnt)
			lastlp = &F->set[F->setcnt - 1];
		if (F->pushbool) {
			tmp = F->set[F->setcnt];
			F->set[F->setcnt] = F->set[F->pushback];
			F->set[F->pushback] = tmp;
			F->pushbool = 0;
			continue;
		}
		if ((bp = fgetln(F->fp, &len)) == NULL)
			return;
		if (lp->linealloc <= len + 1) {
			lp->linealloc += MAX(100, len + 1 - lp->linealloc);
			if ((lp->line =
			    realloc(lp->line, lp->linealloc)) == NULL)
				err(1, NULL);
		}
		memmove(lp->line, bp, len);

		/* Replace trailing newline, if it exists. */
		if (bp[len - 1] == '\n')
			lp->line[len - 1] = '\0';
		else
			lp->line[len] = '\0';
		bp = lp->line;

		/* Split the line into fields, allocate space as necessary. */
		lp->fieldcnt = 0;
		while ((fieldp = mbssep(&bp, tabchar)) != NULL) {
			if (spans && *fieldp == '\0')
				continue;
			if (lp->fieldcnt == lp->fieldalloc) {
				lp->fieldalloc += 50;
				if ((lp->fields = realloc(lp->fields,
				    lp->fieldalloc * sizeof(char *))) == NULL)
					err(1, NULL);
			}
			lp->fields[lp->fieldcnt++] = fieldp;
		}

		/* See if the join field value has changed. */
		if (lastlp != NULL && cmp(lp, F->joinf, lastlp, F->joinf)) {
			F->pushbool = 1;
			F->pushback = F->setcnt;
			break;
		}
	}
}
Exemplo n.º 7
0
void testMassFunctions()
{
  dMass m;
  int i,j;
  dReal q[NUMP][3];		// particle positions
  dReal pm[NUMP];		// particle masses
  dMass m1,m2;
  dMatrix3 R;

  HEADER;

  printf ("\t");
  dMassSetZero (&m);
  TRAP_MESSAGE (dMassSetParameters (&m,10, 0,0,0, 1,2,3, 4,5,6),
		printf (" FAILED (1)\n"), printf (" passed (1)\n"));

  printf ("\t");
  dMassSetZero (&m);
  TRAP_MESSAGE (dMassSetParameters (&m,10, 0.1,0.2,0.15, 3,5,14, 3.1,3.2,4),
		printf ("passed (2)\n") , printf (" FAILED (2)\n"));
  if (m.mass==10 && m.c[0]==REAL(0.1) && m.c[1]==REAL(0.2) &&
      m.c[2]==REAL(0.15) && m._I(0,0)==3 && m._I(1,1)==5 && m._I(2,2)==14 &&
      m._I(0,1)==REAL(3.1) && m._I(0,2)==REAL(3.2) && m._I(1,2)==4 &&
      m._I(1,0)==REAL(3.1) && m._I(2,0)==REAL(3.2) && m._I(2,1)==4)
    printf ("\tpassed (3)\n"); else printf ("\tFAILED (3)\n");

  dMassSetZero (&m);
  dMassSetSphere (&m,1.4, 0.86);
  if (cmp(m.mass,3.73002719949386) && m.c[0]==0 && m.c[1]==0 && m.c[2]==0 &&
      cmp(m._I(0,0),1.10349124669826) &&
      cmp(m._I(1,1),1.10349124669826) &&
      cmp(m._I(2,2),1.10349124669826) &&
      m._I(0,1)==0 && m._I(0,2)==0 && m._I(1,2)==0 &&
      m._I(1,0)==0 && m._I(2,0)==0 && m._I(2,1)==0)
    printf ("\tpassed (4)\n"); else printf ("\tFAILED (4)\n");

  dMassSetZero (&m);
  dMassSetCapsule (&m,1.3,1,0.76,1.53);
  if (cmp(m.mass,5.99961928996029) && m.c[0]==0 && m.c[1]==0 && m.c[2]==0 &&
      cmp(m._I(0,0),1.59461986077384) &&
      cmp(m._I(1,1),4.21878433864904) &&
      cmp(m._I(2,2),4.21878433864904) &&
      m._I(0,1)==0 && m._I(0,2)==0 && m._I(1,2)==0 &&
      m._I(1,0)==0 && m._I(2,0)==0 && m._I(2,1)==0)
    printf ("\tpassed (5)\n"); else printf ("\tFAILED (5)\n");

  dMassSetZero (&m);
  dMassSetBox (&m,0.27,3,4,5);
  if (cmp(m.mass,16.2) && m.c[0]==0 && m.c[1]==0 && m.c[2]==0 &&
      cmp(m._I(0,0),55.35) && cmp(m._I(1,1),45.9) && cmp(m._I(2,2),33.75) &&
      m._I(0,1)==0 && m._I(0,2)==0 && m._I(1,2)==0 &&
      m._I(1,0)==0 && m._I(2,0)==0 && m._I(2,1)==0)
    printf ("\tpassed (6)\n"); else printf ("\tFAILED (6)\n");

  // test dMassAdjust?

  // make random particles and compute the mass, COM and inertia, then
  // translate and repeat.
  for (i=0; i<NUMP; i++) {
    pm[i] = dRandReal()+0.5;
    for (j=0; j<3; j++) {
      q[i][j] = 2.0*(dRandReal()-0.5);
    }
  }
  computeMassParams (&m1,q,pm);
  memcpy (&m2,&m1,sizeof(dMass));
  dMassTranslate (&m2,1,2,-3);
  for (i=0; i<NUMP; i++) {
    q[i][0] += 1;
    q[i][1] += 2;
    q[i][2] -= 3;
  }
  computeMassParams (&m1,q,pm);
  compareMassParams (&m1,&m2,"7");

  // rotate the masses
  _R(0,0) = -0.87919618797635;
  _R(0,1) = 0.15278881840384;
  _R(0,2) = -0.45129772879842;
  _R(1,0) = -0.47307856232664;
  _R(1,1) = -0.39258064912909;
  _R(1,2) = 0.78871864932708;
  _R(2,0) = -0.05666336483842;
  _R(2,1) = 0.90693771059546;
  _R(2,2) = 0.41743652473765;
  dMassRotate (&m2,R);
  for (i=0; i<NUMP; i++) {
    dReal a[3];
    dMultiply0 (a,&_R(0,0),&q[i][0],3,3,1);
    q[i][0] = a[0];
    q[i][1] = a[1];
    q[i][2] = a[2];
  }
  computeMassParams (&m1,q,pm);
  compareMassParams (&m1,&m2,"8");
}
Exemplo n.º 8
0
Arquivo: value.c Projeto: 1ack/Impala
int
avro_value_cmp_fast(avro_value_t *val1, avro_value_t *val2)
{
	avro_type_t  type1 = avro_value_get_type(val1);
	avro_type_t  type2 = avro_value_get_type(val2);
	if (type1 != type2) {
		return -1;
	}

	switch (type1) {
		case AVRO_BOOLEAN:
		{
			int  v1;
			int  v2;
			check_return(0, avro_value_get_boolean(val1, &v1));
			check_return(0, avro_value_get_boolean(val2, &v2));
			return cmp(!!v1, !!v2);
		}

		case AVRO_BYTES:
		{
			const void  *buf1;
			const void  *buf2;
			size_t  size1;
			size_t  size2;
			size_t  min_size;
			int  result;

			check_return(0, avro_value_get_bytes(val1, &buf1, &size1));
			check_return(0, avro_value_get_bytes(val2, &buf2, &size2));

			min_size = (size1 < size2)? size1: size2;
			result = memcmp(buf1, buf2, min_size);
			if (result != 0) {
				return result;
			} else {
				return cmp(size1, size2);
			}
		}

		case AVRO_DOUBLE:
		{
			double  v1;
			double  v2;
			check_return(0, avro_value_get_double(val1, &v1));
			check_return(0, avro_value_get_double(val2, &v2));
			return cmp(v1, v2);
		}

		case AVRO_FLOAT:
		{
			float  v1;
			float  v2;
			check_return(0, avro_value_get_float(val1, &v1));
			check_return(0, avro_value_get_float(val2, &v2));
			return cmp(v1, v2);
		}

		case AVRO_INT32:
		{
			int32_t  v1;
			int32_t  v2;
			check_return(0, avro_value_get_int(val1, &v1));
			check_return(0, avro_value_get_int(val2, &v2));
			return cmp(v1, v2);
		}

		case AVRO_INT64:
		{
			int64_t  v1;
			int64_t  v2;
			check_return(0, avro_value_get_long(val1, &v1));
			check_return(0, avro_value_get_long(val2, &v2));
			return cmp(v1, v2);
		}

		case AVRO_NULL:
		{
			check_return(0, avro_value_get_null(val1));
			check_return(0, avro_value_get_null(val2));
			return 0;
		}

		case AVRO_STRING:
		{
			const char  *buf1;
			const char  *buf2;
			size_t  size1;
			size_t  size2;
			size_t  min_size;
			int  result;
			check_return(0, avro_value_get_string(val1, &buf1, &size1));
			check_return(0, avro_value_get_string(val2, &buf2, &size2));

			min_size = (size1 < size2)? size1: size2;
			result = memcmp(buf1, buf2, min_size);
			if (result != 0) {
				return result;
			} else {
				return cmp(size1, size2);
			}
		}

		case AVRO_ARRAY:
		{
			size_t  count1;
			size_t  count2;
			size_t  min_count;
			size_t  i;
			check_return(0, avro_value_get_size(val1, &count1));
			check_return(0, avro_value_get_size(val2, &count2));

			min_count = (count1 < count2)? count1: count2;
			for (i = 0; i < min_count; i++) {
				avro_value_t  child1;
				avro_value_t  child2;
				int  result;
				check_return(0, avro_value_get_by_index
					     (val1, i, &child1, NULL));
				check_return(0, avro_value_get_by_index
					     (val2, i, &child2, NULL));
				result = avro_value_cmp_fast(&child1, &child2);
				if (result != 0) {
					return result;
				}
			}

			return cmp(count1, count2);
		}

		case AVRO_ENUM:
		{
			int  v1;
			int  v2;
			check_return(0, avro_value_get_enum(val1, &v1));
			check_return(0, avro_value_get_enum(val2, &v2));
			return cmp(v1, v2);
		}

		case AVRO_FIXED:
		{
			const void  *buf1;
			const void  *buf2;
			size_t  size1;
			size_t  size2;
			check_return(0, avro_value_get_fixed(val1, &buf1, &size1));
			check_return(0, avro_value_get_fixed(val2, &buf2, &size2));
			if (size1 != size2) {
				return -1;
			}
			return memcmp(buf1, buf2, size1);
		}

		case AVRO_MAP:
		{
			return -1;
		}

		case AVRO_RECORD:
		{
			size_t  count1;
			check_return(0, avro_value_get_size(val1, &count1));

			size_t  i;
			for (i = 0; i < count1; i++) {
				avro_value_t  child1;
				avro_value_t  child2;
				int  result;

				check_return(0, avro_value_get_by_index
					     (val1, i, &child1, NULL));
				check_return(0, avro_value_get_by_index
					     (val2, i, &child2, NULL));
				result = avro_value_cmp_fast(&child1, &child2);
				if (result != 0) {
					return result;
				}
			}

			return 0;
		}

		case AVRO_UNION:
		{
			int  disc1;
			int  disc2;
			check_return(0, avro_value_get_discriminant(val1, &disc1));
			check_return(0, avro_value_get_discriminant(val2, &disc2));

			if (disc1 == disc2) {
				avro_value_t  branch1;
				avro_value_t  branch2;
				check_return(0, avro_value_get_current_branch(val1, &branch1));
				check_return(0, avro_value_get_current_branch(val2, &branch2));
				return avro_value_cmp_fast(&branch1, &branch2);
			} else {
				return cmp(disc1, disc2);
			}
		}

		default:
			return 0;
	}
}
Exemplo n.º 9
0
 virtual bool eq(const Object *rhs)const override { return cmp(rhs) == 0; }
int main(void)
{

	number_passed = 0;
	number_failed = 0;

	int data_read;

	printf("\n\n");
	delay(1000);

	data_read = read(SIM_HOST_BASE_ADDR + HOST_SLAVE_CONTROL_BASE + HOST_SLAVE_VERSION_REG); // 225
	printf("Host Version number = 0x%0X\n", data_read);
	data_read = read(SIM_SLAVE_BASE_ADDR + HOST_SLAVE_CONTROL_BASE + HOST_SLAVE_VERSION_REG); // 481
	printf("Slave Version number = 0x%0X\n", data_read);

	printf("Testing host register read/write \n");
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_LINE_CONTROL_REG, 0x18); // 2
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_LINE_CONTROL_REG, 0x18); // 2
	printf("Testing slave register read/write \n");
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG, 0x70); // 336
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG , 0x70); // 336

	printf("Testing register reset \n");
	write(SIM_HOST_BASE_ADDR + HOST_SLAVE_CONTROL_BASE + HOST_SLAVE_CONTROL_REG, 0x2); // 224
	write(SIM_SLAVE_BASE_ADDR + HOST_SLAVE_CONTROL_BASE + HOST_SLAVE_CONTROL_REG, 0x2); // 480
	delay(1000);
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_LINE_CONTROL_REG, 0x00); // 2
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG, 0x00); // 336
	delay(1000);

	printf("Configure host and slave mode.\n");
	write(SIM_HOST_BASE_ADDR + HOST_SLAVE_CONTROL_BASE + HOST_SLAVE_CONTROL_REG, 0x1);
	write(SIM_SLAVE_BASE_ADDR + HOST_SLAVE_CONTROL_BASE + HOST_SLAVE_CONTROL_REG, 0x0);

	printf("Connect full speed\n");
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_LINE_CONTROL_REG, 0x18);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG, 0x70);
	delay(20000);
	//expecting connection event interrupt
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x04);
	//expecting full speed connect
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + RX_CONNECT_STATE_REG, 0x02);
	//expecting change in reset state event, and change in vbus state event
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x24);
	//expecting full speed connect and vbus present
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_LINE_STATUS_REG, 0x06);

	printf("Cancel interrupts\n");
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x04);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x24);
	//expecting all interrupts cancelled
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x00);
	//expecting all interrupts cancelled
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x00);
	delay(1000);

	printf("Disconnect\n");
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_LINE_CONTROL_REG, 0x18);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG , 0x30);
	delay(10000);
	//expecting connection event interrupt
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x04);
	//expecting disconnect state
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + RX_CONNECT_STATE_REG, 0x00);
	//expecting change in reset state event
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x04);
	//expecting vbus present, and disconnect state
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_LINE_STATUS_REG, 0x04);
	//cancel interrupts
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x04);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x04);

	printf("Connect full speed\n");
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_LINE_CONTROL_REG, 0x18);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG, 0x70);
	delay(20000);
	//expecting connection event interrupt
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x04);
	//expecting full speed connect
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + RX_CONNECT_STATE_REG, 0x02);
	//expecting change in reset state event
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x04);
	//expecting full speed connect and vbus present
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_LINE_STATUS_REG, 0x06);
	//cancel interrupts
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x04);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x04);
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x00);
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x00);
	delay(1000);

	printf("Host forcing reset\n");
	write(SIM_HOST_BASE_ADDR + HCREG_BASE+TX_LINE_CONTROL_REG, 0x1c);
	delay(20000);
	//expecting change in reset state event
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x04);
	//expecting vbus present, and disconnect state
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_LINE_STATUS_REG, 0x04);
	//cancel interrupt
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x04);

	printf("Connect full speed\n");
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_LINE_CONTROL_REG, 0x18);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG, 0x70);
	delay(20000);
	//expecting no host interrupts
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x00);
	//expecting full speed connect
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + RX_CONNECT_STATE_REG, 0x02);
	//expecting change in reset state event
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x04);
	//expecting full speed connect and vbus present
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_LINE_STATUS_REG, 0x06);
	//cancel interrupts
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x04);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x04);
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x00);
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x00);
	delay(1000);

	printf("Trans test: Device address = 0x00, 2 byte SETUP transaction to Endpoint 0.\n");
	int USBAddress = 0x00;
	int USBEndPoint = 0x00;
	int transType = SETUP_TRANS;
	int dataSize = 2;
	//enable endpoint, and make ready
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG, 0x71);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_ADDRESS, USBAddress);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + EP0_CTRL_REG, 0x03);
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_ADDR_REG, USBAddress);
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_ENDP_REG, USBEndPoint);
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_TRANS_TYPE_REG, transType);
	int data = 0x00;
	int i;
	for (i=0; i<dataSize; i=i+1)
	{
		write(SIM_HOST_BASE_ADDR + HOST_TX_FIFO_BASE + FIFO_DATA_REG, data);
		data = data + 1;
	}
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_CONTROL_REG, 0x01);
	delay(20000);
	//expecting transaction done interrupt
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x01);
	//expecting transaction done interrupt
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x01);
	//endpoint enabled, and endpoint ready cleared
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + EP0_CTRL_REG, 0x01);
	printf("Checking receive data\n");
	data = 0x00;
	for (i=0; i<dataSize; i=i+1) 
	{
		cmp(SIM_SLAVE_BASE_ADDR + EP0_RX_FIFO_BASE + FIFO_DATA_REG, data);
		data = data + 1;
	}

	printf("Trans test: Device address = 0x5a, 20 byte OUT DATA0 transaction to Endpoint 1.\n");
	USBAddress = 0x5a;
	USBEndPoint = 0x01;
	transType = OUTDATA0_TRANS;
	dataSize = 20;
	//enable endpoint, and make ready
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG, 0x71);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_ADDRESS, USBAddress);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + EP1_CTRL_REG, 0x03);
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_ADDR_REG, USBAddress);
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_ENDP_REG, USBEndPoint);
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_TRANS_TYPE_REG, transType);
	data = 0x00;
	for (i=0; i<dataSize; i=i+1)
	{
		write(SIM_HOST_BASE_ADDR + HOST_TX_FIFO_BASE + FIFO_DATA_REG, data);
		data = data + 1;
	}
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_CONTROL_REG, 0x01);
	delay(20000);
	//expecting transaction done interrupt
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x01);
	//expecting transaction done interrupt
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x01);
	//endpoint enabled, and endpoint ready cleared
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + EP1_CTRL_REG, 0x01);
	printf("Checking receive data\n");
	data = 0x00;
	for (i=0; i<dataSize; i=i+1)
	{
		cmp(SIM_SLAVE_BASE_ADDR + EP1_RX_FIFO_BASE + FIFO_DATA_REG, data);
		data = data + 1;
	}

	printf("Trans test: Device address = 0x01, 2 byte IN transaction to Endpoint 2.\n");
	USBAddress = 0x01;
	USBEndPoint = 0x02;
	transType = IN_TRANS;
	dataSize = 2;
	//enable endpoint, and make ready
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_CONTROL_REG, 0x71);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_ADDRESS, USBAddress);
	write(SIM_SLAVE_BASE_ADDR + SCREG_BASE + EP2_CTRL_REG, 0x03);
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_ADDR_REG, USBAddress);
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_ENDP_REG, USBEndPoint);
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_TRANS_TYPE_REG, transType);
	data = 0x00;
	for (i=0; i<dataSize; i=i+1)
	{
		write(SIM_SLAVE_BASE_ADDR + EP2_TX_FIFO_BASE + FIFO_DATA_REG, data);
		data = data + 1;
	}
	write(SIM_HOST_BASE_ADDR + HCREG_BASE + TX_CONTROL_REG, 0x01);
	delay(20000);
	//expecting transaction done interrupt
	cmp(SIM_HOST_BASE_ADDR + HCREG_BASE + INTERRUPT_STATUS_REG, 0x01);
	//expecting transaction done interrupt
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + SC_INTERRUPT_STATUS_REG, 0x01);
	//endpoint enabled, and endpoint ready cleared
	cmp(SIM_SLAVE_BASE_ADDR + SCREG_BASE + EP2_CTRL_REG, 0x01);
	printf("Checking receive data\n");
	data = 0x00;
	for (i=0; i<dataSize; i=i+1)
	{
		cmp(SIM_HOST_BASE_ADDR + HOST_RX_FIFO_BASE + FIFO_DATA_REG, data);
		data = data + 1;
	}

	printf("Finished all tests (%d passed, %d failed)\n", 
			number_passed, number_failed);

	// delay loop
	for (i=0; i<1000; i++) {}

	// end simulation by writing exit sequence
	printf("%c", SIM_END_SEQ);

	return(0);
}
Exemplo n.º 11
0
void GetReady::readTFGene(GeneIM temp_gene_IM[],double **old_GRN,string TF_Gene_address)
{
    ifstream data(TF_Gene_address.c_str());
	char ch;
	int i,num=0;
	char *Name;
	char STRING1[GENEAM][10];
	data.get(ch);
	for(i=gene_amount;i<GENEAM;)
	{
		int a,b;
		while(ch=='#')
		{
			string noUse;
			getline(data,noUse);
			data.get(ch);
		}
		while(ch!='	')
		{
			STRING1[i][num]=ch;
			data.get(ch);
			num++;
		}
		STRING1[i][num]='\0';
		Name=STRING1[i];
		int j;
		for(j=0;j<i;j++)
		{
            lwr(Name);
            if(cmp(temp_gene_IM[j].gene_name,Name)==0)
			{
				a=j;
				j=i+1;
			}
		}
		if(j==i)
		{
			temp_gene_IM[i].name=Name;
			temp_gene_IM[i].putName();
			temp_gene_IM[i].gene_number=i;
			a=i;
			i++;
		}
		data.get(ch);
		num=0;
		while(ch!='	')
		{
			STRING1[i][num]=ch;
			data.get(ch);
			num++;
		}
		STRING1[i][num]='\0';
		Name=STRING1[i];
		for(j=0;j<i;j++)
		{
            lwr(Name);
            if(cmp(temp_gene_IM[j].gene_name,Name)==0)
			{
				b=j;
				j=i+1;
			}
		}
		if(j==i)
		{
			temp_gene_IM[i].name=Name;
			temp_gene_IM[i].putName();
			temp_gene_IM[i].gene_number=i;
			b=i;
			i++;
		}
		data.get(ch);
		if(ch=='-')
		{
			if(old_GRN[b][a]==1||old_GRN[b][a]==2)
			{
                if(old_GRN[b][a]!=2)
                    uncertain<<"?\t"<<temp_gene_IM[b].getGeneName()<<"->"<<temp_gene_IM[a].getGeneName()<<endl;
                old_GRN[b][a]=2;
				uncertain_row.push_back(b);
				uncertain_column.push_back(a);
				unknow++;
			}
			else
				old_GRN[b][a]=-1;
		}
		else if(ch=='+')
		{
			data.get(ch);
			if(ch=='-')
			{
				old_GRN[b][a]=2;
				uncertain_row.push_back(b);
				uncertain_column.push_back(a);
				uncertain<<"?\t"<<temp_gene_IM[b].getGeneName()<<"->"<<temp_gene_IM[a].getGeneName()<<endl;
				unknow++;
			}
			else
				old_GRN[b][a]=1;
		}
		else
			old_GRN[b][a]=0;
		string noUse;
		getline(data,noUse);
		num=0;
		if(!data.get(ch))
		{
			gene_amount=i;
			i=GENEAM;
		}
	}
}
Exemplo n.º 12
0
void receive_matx32d(cv::Matx32d matx)
{
    double t[6] = {0.445, 0.473, 0.765, 0.523, 0.832, 0.345};
    cmp(matx, t);
}
Exemplo n.º 13
0
bool Resultado::operator<(const Resultado& r) const {
	return (cmp(this->J, r.J) < 0);
}
Exemplo n.º 14
0
double Resultado::atualizaJ(const Repositorio& repositorio) {
	double novoJ = calculaJ(repositorio);
	assert(cmp(novoJ,this->J) <= 0);
	return (this->J = novoJ);
}
Exemplo n.º 15
0
//除法计算
void divid(const char a[],const char b[],char result[])
{
    bool isNegative = false;
    char *op1,*pa,*pb,*pr;
    int up,alen,blen,adotp,bdotp,i,k,dotp,t,t1,j,quo_size;
    /////////////判定符号///////////////
    //如果为异号
    if((a[0] == '-'||b[0] == '-')&&a[0] != b[0])
        result[0] = '-',isNegative = true;
    
    //去除负号
    if(a[0] == '-')a++;
    if(b[0] == '-')b++;
    ///////////////////////////////////
    
    alen = strlen(a)-1; //减去一位小数点
    blen = strlen(b)-1;
    
    ///////获取被除数小数点移位后的位置//////////
    adotp = strchr(a,'.')-a;
    bdotp = strchr(b,'.')-b;
    
    //计算商小数点位置
    dotp = adotp+blen-bdotp;
    if(isNegative)dotp++;
    
    //////////准备数据/////////////
    op1 = (char *)calloc(alen+blen+1,sizeof(char));
    pa = (char *)calloc(alen+blen+1,sizeof(char));
    pb = (char *)calloc(blen+1,sizeof(char));
    pr = (char *)calloc(alen+blen+1,sizeof(char));
    
    for(i = 0,t=0; i<=alen; i++)
    {
        if(a[i]!='.')
            pa[t++] = a[i];
    }
    for(;t<dotp-1;t++)
    {
        pa[t] = '0';
    }
    for(;t<blen;t++)
    {
        pa[t] = '0';
    }
    
    pa[t] = '\0';
    for(i = 0,t=0; i<=blen; i++)
    {
        if(b[i]!='.')
            pb[t++] = b[i];
    }
    pb[t] = '\0';
    clz(pa);
    clz(pb);
    ////////取得被除数的高位数op1,且op1大于被除数b//////////
    strncpy(op1,pa,strlen(pb));
    if(strcmp(op1,pb)<0)
    {
        strncpy(op1,pa,strlen(pb)+1);
    }
    
    /////计算//////
    j = k = strlen(op1);
    t1=0;
    quo_size = strlen(pa)+1-k; //获取商的长度
    
    while(t1<quo_size)
    {
        up = 0;
        t = cmp(op1,pb);
        while(t>=0)
        {
            dsub(op1,pb);
            t = cmp(op1,pb);
            up++;
        }
        pr[t1++] = up+'0';
        op1[strlen(op1)]=pa[j++];
        clz(op1);
    }
    quo_size+=50;//加50精度
    while(t1<quo_size&&(cmp(op1,(char *)"0")>0))
    {
        up = 0;
        op1[strlen(op1)]='0';
        t = cmp(op1,pb);
        while(t>=0)
        {
            dsub(op1,pb);
            t = cmp(op1,pb);
            up++;
        }
        pr[t1++] = up+'0';                    
    }
    //////////////////////////////
    
    if(isNegative)t=1;
    else t=0;
    for(i=0;i<=t1;i++)//复制结果并给商加上小数点
    {
        if(t==dotp) result[t++] = '.';
        result[t++]=pr[i];
    }   
    
    
    clz(result);
    clDot(result);
    free(op1);
    free(pa);
    free(pb);
}
Exemplo n.º 16
0
 int Group::cmp(const basic_group<Element>* other) const {
  int ct = cmpTypes(*this, *other);
  if (ct != 0) return ct;
  const Group* c = static_cast<const Group*>(other);
  return cmp(*c);
 }
Exemplo n.º 17
0
int
main(int argc, char *argv[])
{
	INPUT *F1, *F2;
	int aflag, ch, cval, vflag;
	char *end;

	setlocale(LC_ALL, "");

	F1 = &input1;
	F2 = &input2;

	aflag = vflag = 0;
	obsolete(argv);
	while ((ch = getopt(argc, argv, "\01a:e:j:1:2:o:t:v:")) != -1) {
		switch (ch) {
		case '\01':		/* See comment in obsolete(). */
			aflag = 1;
			F1->unpair = F2->unpair = 1;
			break;
		case '1':
			if ((F1->joinf = strtol(optarg, &end, 10)) < 1)
				errx(1, "-1 option field number less than 1");
			if (*end)
				errx(1, "illegal field number -- %s", optarg);
			--F1->joinf;
			break;
		case '2':
			if ((F2->joinf = strtol(optarg, &end, 10)) < 1)
				errx(1, "-2 option field number less than 1");
			if (*end)
				errx(1, "illegal field number -- %s", optarg);
			--F2->joinf;
			break;
		case 'a':
			aflag = 1;
			switch(strtol(optarg, &end, 10)) {
			case 1:
				F1->unpair = 1;
				break;
			case 2:
				F2->unpair = 1;
				break;
			default:
				errx(1, "-a option file number not 1 or 2");
				break;
			}
			if (*end)
				errx(1, "illegal file number -- %s", optarg);
			break;
		case 'e':
			empty = optarg;
			break;
		case 'j':
			if ((F1->joinf = F2->joinf =
			    strtol(optarg, &end, 10)) < 1)
				errx(1, "-j option field number less than 1");
			if (*end)
				errx(1, "illegal field number -- %s", optarg);
			--F1->joinf;
			--F2->joinf;
			break;
		case 'o':
			fieldarg(optarg);
			break;
		case 't':
			spans = 0;
			if (mbrtowc(&tabchar[0], optarg, MB_LEN_MAX, NULL) !=
			    strlen(optarg))
				errx(1, "illegal tab character specification");
			tabchar[1] = L'\0';
			break;
		case 'v':
			vflag = 1;
			joinout = 0;
			switch (strtol(optarg, &end, 10)) {
			case 1:
				F1->unpair = 1;
				break;
			case 2:
				F2->unpair = 1;
				break;
			default:
				errx(1, "-v option file number not 1 or 2");
				break;
			}
			if (*end)
				errx(1, "illegal file number -- %s", optarg);
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (aflag && vflag)
		errx(1, "the -a and -v options are mutually exclusive");

	if (argc != 2)
		usage();

	/* Open the files; "-" means stdin. */
	if (!strcmp(*argv, "-"))
		F1->fp = stdin;
	else if ((F1->fp = fopen(*argv, "r")) == NULL)
		err(1, "%s", *argv);
	++argv;
	if (!strcmp(*argv, "-"))
		F2->fp = stdin;
	else if ((F2->fp = fopen(*argv, "r")) == NULL)
		err(1, "%s", *argv);
	if (F1->fp == stdin && F2->fp == stdin)
		errx(1, "only one input file may be stdin");

	slurp(F1);
	slurp(F2);
	while (F1->setcnt && F2->setcnt) {
		cval = cmp(F1->set, F1->joinf, F2->set, F2->joinf);
		if (cval == 0) {
			/* Oh joy, oh rapture, oh beauty divine! */
			if (joinout)
				joinlines(F1, F2);
			slurp(F1);
			slurp(F2);
		} else if (cval < 0) {
			/* File 1 takes the lead... */
			if (F1->unpair)
				joinlines(F1, NULL);
			slurp(F1);
		} else {
			/* File 2 takes the lead... */
			if (F2->unpair)
				joinlines(F2, NULL);
			slurp(F2);
		}
	}

	/*
	 * Now that one of the files is used up, optionally output any
	 * remaining lines from the other file.
	 */
	if (F1->unpair)
		while (F1->setcnt) {
			joinlines(F1, NULL);
			slurp(F1);
		}
	if (F2->unpair)
		while (F2->setcnt) {
			joinlines(F2, NULL);
			slurp(F2);
		}
	exit(0);
}
Exemplo n.º 18
0
template <class Phenotype> inline void population<Phenotype>::sort() {
    compare_members cmp(a);
    std::sort(pvec.begin(), pvec.end(), cmp);
}
Exemplo n.º 19
0
ATTRIBUTE_CLIB_SECTION
void
qsort(void *a, size_t n, size_t es, cmp_t *cmp)
{
	char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
	int d, r, swap_cnt;

loop:
	swap_cnt = 0;
	if (n < 7) {
		for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
			for (pl = pm; pl > (char *)a && cmp(pl - es, pl) > 0;
			     pl -= es)
				swap(pl, pl - es);
		return;
	}
	pm = (char *)a + (n / 2) * es;
	if (n > 7) {
		pl = a;
		pn = (char *)a + (n - 1) * es;
		if (n > 40) {
			d = (n / 8) * es;
			pl = med3(pl, pl + d, pl + 2 * d, cmp);
			pm = med3(pm - d, pm, pm + d, cmp);
			pn = med3(pn - 2 * d, pn - d, pn, cmp);
		}
		pm = med3(pl, pm, pn, cmp);
	}
	swap(a, pm);
	pa = pb = (char *)a + es;

	pc = pd = (char *)a + (n - 1) * es;
	for (;;) {
		while (pb <= pc && (r = cmp(pb, a)) <= 0) {
			if (r == 0) {
				swap_cnt = 1;
				swap(pa, pb);
				pa += es;
			}
			pb += es;
		}
		while (pb <= pc && (r = cmp(pc, a)) >= 0) {
			if (r == 0) {
				swap_cnt = 1;
				swap(pc, pd);
				pd -= es;
			}
			pc -= es;
		}
		if (pb > pc)
			break;
		swap(pb, pc);
		swap_cnt = 1;
		pb += es;
		pc -= es;
	}
	if (swap_cnt == 0) {  /* Switch to insertion sort */
		for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
			for (pl = pm; pl > (char *)a && cmp(pl - es, pl) > 0;
			     pl -= es)
				swap(pl, pl - es);
		return;
	}

	pn = (char *)a + n * es;
	r = min(pa - (char *)a, pb - pa);
	vecswap(a, pb - r, r);
	r = min(pd - pc, pn - pd - es);
	vecswap(pb, pn - r, r);
	if ((r = pb - pa) > es)
		qsort(a, r / es, es, cmp);
	if ((r = pd - pc) > es) {
		/* Iterate rather than recurse to save stack space */
		a = pn - r;
		n = r / es;
		goto loop;
	}
/*		qsort(pn - r, r / es, es, cmp);*/
}
Exemplo n.º 20
0
void C1_MacroAssembler::allocate_array(
  Register obj,                        // result: pointer to array after successful allocation
  Register len,                        // array length
  Register t1,                         // temp register
  Register t2,                         // temp register
  Register t3,                         // temp register
  int      hdr_size,                   // object header size in words
  int      elt_size,                   // element size in bytes
  Register klass,                      // object klass
  Label&   slow_case                   // continuation point if fast allocation fails
) {
  assert_different_registers(obj, len, t1, t2, t3, klass);
  assert(klass == G5, "must be G5");
  assert(t1 == G1, "must be G1");

  // determine alignment mask
  assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");

  // check for negative or excessive length
  // note: the maximum length allowed is chosen so that arrays of any
  //       element size with this length are always smaller or equal
  //       to the largest integer (i.e., array size computation will
  //       not overflow)
  set(max_array_allocation_length, t1);
  cmp(len, t1);
  br(Assembler::greaterUnsigned, false, Assembler::pn, slow_case);

  // compute array size
  // note: if 0 <= len <= max_length, len*elt_size + header + alignment is
  //       smaller or equal to the largest integer; also, since top is always
  //       aligned, we can do the alignment here instead of at the end address
  //       computation
  const Register arr_size = t1;
  switch (elt_size) {
    case  1: delayed()->mov(len,    arr_size); break;
    case  2: delayed()->sll(len, 1, arr_size); break;
    case  4: delayed()->sll(len, 2, arr_size); break;
    case  8: delayed()->sll(len, 3, arr_size); break;
    default: ShouldNotReachHere();
  }
  add(arr_size, hdr_size * wordSize + MinObjAlignmentInBytesMask, arr_size); // add space for header & alignment
  and3(arr_size, ~MinObjAlignmentInBytesMask, arr_size);                     // align array size

  // allocate space & initialize header
  if (UseTLAB) {
    tlab_allocate(obj, arr_size, 0, t2, slow_case);
  } else {
    eden_allocate(obj, arr_size, 0, t2, t3, slow_case);
  }
  initialize_header(obj, klass, len, t2, t3);

  // initialize body
  const Register base  = t2;
  const Register index = t3;
  add(obj, hdr_size * wordSize, base);               // compute address of first element
  sub(arr_size, hdr_size * wordSize, index);         // compute index = number of words to clear
  initialize_body(base, index);

  if (CURRENT_ENV->dtrace_alloc_probes()) {
    assert(obj == O0, "must be");
    call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),
         relocInfo::runtime_call_type);
    delayed()->nop();
  }

  verify_oop(obj);
}
Exemplo n.º 21
0
static Eterm
keyfind(int Bif, Process* p, Eterm Key, Eterm Pos, Eterm List)
{
    int max_iter = 10 * CONTEXT_REDS;
    Sint pos;
    Eterm term;

    if (!is_small(Pos) || (pos = signed_val(Pos)) < 1) {
	BIF_ERROR(p, BADARG);
    }

    if (is_small(Key)) {
	double float_key = (double) signed_val(Key);

	while (is_list(List)) {
	    if (--max_iter < 0) {
		BUMP_ALL_REDS(p);
		BIF_TRAP3(bif_export[Bif], p, Key, Pos, List);
	    }
	    term = CAR(list_val(List));
	    List = CDR(list_val(List));
	    if (is_tuple(term)) {
		Eterm *tuple_ptr = tuple_val(term);
		if (pos <= arityval(*tuple_ptr)) {
		    Eterm element = tuple_ptr[pos];
		    if (Key == element) {
			return term;
		    } else if (is_float(element)) {
			FloatDef f;

			GET_DOUBLE(element, f);
			if (f.fd == float_key) {
			    return term;
			}
		    }
		}
	    }
	}
    } else if (is_immed(Key)) {
	while (is_list(List)) {
	    if (--max_iter < 0) {
		BUMP_ALL_REDS(p);
		BIF_TRAP3(bif_export[Bif], p, Key, Pos, List);
	    }
	    term = CAR(list_val(List));
	    List = CDR(list_val(List));
	    if (is_tuple(term)) {
		Eterm *tuple_ptr = tuple_val(term);
		if (pos <= arityval(*tuple_ptr)) {
		    Eterm element = tuple_ptr[pos];
		    if (Key == element) {
			return term;
		    }
		}
	    }
	}
    } else {
	while (is_list(List)) {
	    if (--max_iter < 0) {
		BUMP_ALL_REDS(p);
		BIF_TRAP3(bif_export[Bif], p, Key, Pos, List);
	    }
	    term = CAR(list_val(List));
	    List = CDR(list_val(List));
	    if (is_tuple(term)) {
		Eterm *tuple_ptr = tuple_val(term);
		if (pos <= arityval(*tuple_ptr)) {
		    Eterm element = tuple_ptr[pos];
		    if (cmp(Key, element) == 0) {
			return term;
		    }
		}
	    }
	}
    }

    if (is_not_nil(List))  {
	BIF_ERROR(p, BADARG);
    }
    return am_false;
}
static Char* bm_med3 ( Char* a, Char* b, Char* c, 
                       Int (*cmp)(void*,void*) ) {
   return cmp(a, b) < 0
          ? (cmp(b, c) < 0 ? b : cmp(a, c) < 0 ? c : a)
          : (cmp(b, c) > 0 ? b : cmp(a, c) > 0 ? c : a);
}
Exemplo n.º 23
0
static int *
med3(int *a, int *b, int *c, double *x)
{	return cmp(a, b, x) < 0 ?
		  (cmp(b, c, x) < 0 ? b : (cmp(a, c, x) < 0 ? c : a ) )
		: (cmp(b, c, x) > 0 ? b : (cmp(a, c, x) < 0 ? a : c ) );
}
static void bm_qsort ( Char* a, SizeT n, SizeT es,
                       Int (*cmp)(void*,void*) )
{
   Char  *pa, *pb, *pc, *pd, *pl, *pm, *pn, *pv;
   Int   r, swaptype;
   Word  t, v;
   SizeT s, s1, s2;
  tailcall:
   BM_SWAPINIT(a, es);
   if (n < 7) {
      for (pm = a + es; pm < a + n*es; pm += es)
         for (pl = pm; pl > a && cmp(pl-es, pl) > 0; pl -= es)
            BM_SWAP(pl, pl-es);
      return;
   }
   pm = a + (n/2)*es;
   if (n > 7) {
      pl = a;
      pn = a + (n-1)*es;
      if (n > 40) {
         s = (n/8)*es;
         pl = bm_med3(pl, pl+s, pl+2*s, cmp);
         pm = bm_med3(pm-s, pm, pm+s, cmp);
         pn = bm_med3(pn-2*s, pn-s, pn, cmp);
      }
      pm = bm_med3(pl, pm, pn, cmp);
   }
   BM_PVINIT(pv, pm);
   pa = pb = a;
   pc = pd = a + (n-1)*es;
   for (;;) {
      while (pb <= pc && (r = cmp(pb, pv)) <= 0) {
         if (r == 0) { BM_SWAP(pa, pb); pa += es; }
         pb += es;
      }
      while (pc >= pb && (r = cmp(pc, pv)) >= 0) {
         if (r == 0) { BM_SWAP(pc, pd); pd -= es; }
         pc -= es;
      }
      if (pb > pc) break;
      BM_SWAP(pb, pc);
      pb += es;
      pc -= es;
   }
   pn = a + n*es;
   s = BM_MIN(pa-a,  pb-pa   ); BM_VECSWAP(a,  pb-s, s);
   s = BM_MIN(pd-pc, pn-pd-es); BM_VECSWAP(pb, pn-s, s);
   /* Now recurse.  Do the smaller partition first with an explicit
      recursion, then do the larger partition using a tail call.
      Except we can't rely on gcc to implement a tail call in any sane
      way, so simply jump back to the start.  This guarantees stack
      growth can never exceed O(log N) even in the worst case. */
   s1 = pb-pa;
   s2 = pd-pc;
   if (s1 < s2) {
      if (s1 > es) {
         bm_qsort(a, s1/es, es, cmp);
      }
      if (s2 > es) {
         /* bm_qsort(pn-s2, s2/es, es, cmp); */
         a = pn-s2; n = s2/es; es = es; cmp = cmp;
         goto tailcall;
      }
   } else {
      if (s2 > es) {
         bm_qsort(pn-s2, s2/es, es, cmp);
      }
      if (s1 > es) {
         /* bm_qsort(a, s1/es, es, cmp); */
         a = a; n = s1/es; es = es; cmp = cmp;
         goto tailcall;
      } 
   }
}
Exemplo n.º 25
0
static int nabors(void)
{
    int tl_null = G_is_d_null_value(&tl);
    int tr_null = G_is_d_null_value(&tr);
    int bl_null = G_is_d_null_value(&bl);
    int br_null = G_is_d_null_value(&br);

    /* if both a and b are NULLs, thery are equal */
#define cmp(a, b) (a##_null+b##_null==1 || (a##_null+b##_null==0 && a != b))

    if (cmp(tl, tr) != 0) {	/* 0, 4, 5, 6, 8, 9, 10 */
	if (cmp(tl, bl) != 0) {	/* 4, 6, 8, 10 */
	    if (cmp(bl, br) != 0) {	/* 8, 10 */
		if (cmp(tr, br) != 0)
		    return (10);
		else
		    return (8);
	    }
	    else {		/* 4, 6 */

		if (cmp(tr, br) != 0)
		    return (6);
		else
		    return (4);
	    }
	}
	else {			/* 0, 5, 9 */

	    if (cmp(bl, br) != 0) {	/* 0, 9 */
		if (cmp(tr, br) != 0)
		    return (9);
		else
		    return (0);
	    }
	    else
		return (5);
	}
    }
    else {			/* 1, 2, 3, 7, 11 */

	if (cmp(tl, bl) != 0) {	/* 2, 3, 7 */
	    if (cmp(bl, br) != 0) {	/* 3, 7 */
		if (cmp(tr, br) != 0)
		    return (7);
		else
		    return (3);
	    }
	    else
		return (2);
	}
	else {			/* 1, 11 */

	    if (cmp(bl, br) != 0)
		return (1);
	    else
		return (11);
	}
    }

    return 0;
}
Exemplo n.º 26
0
/*
 * Find an element e in a sorted 2-3-4 tree t. Returns NULL if not
 * found. e is always passed as the first argument to cmp, so cmp
 * can be an asymmetric function if desired. cmp can also be passed
 * as NULL, in which case the compare function from the tree proper
 * will be used.
 */
void *findrelpos234(tree234 * t, void *e, cmpfn234 cmp, int relation,
		int *index) {
	node234 *n;
	void *ret;
	int c;
	int idx, ecount, kcount, cmpret;

	if (t->root == NULL)
		return NULL;

	if (cmp == NULL)
		cmp = t->cmp;

	n = t->root;
	/*
	 * Attempt to find the element itself.
	 */
	idx = 0;
	ecount = -1;
	/*
	 * Prepare a fake `cmp' result if e is NULL.
	 */
	cmpret = 0;
	if (e == NULL) {
		if (!(relation == REL234_LT || relation == REL234_GT)) {
			return NULL; //zhangbo
		}
		//assert(relation == REL234_LT || relation == REL234_GT);
		if (relation == REL234_LT)
			cmpret = +1; /* e is a max: always greater */
		else if (relation == REL234_GT)
			cmpret = -1; /* e is a min: always smaller */
	}
	while (1) {
		for (kcount = 0; kcount < 4; kcount++) {
			if (kcount >= 3 || n->elems[kcount] == NULL
					|| (c = cmpret ? cmpret : cmp(e, n->elems[kcount])) < 0) {
				break;
			}
			if (n->kids[kcount])
				idx += n->counts[kcount];
			if (c == 0) {
				ecount = kcount;
				break;
			}
			idx++;
		}
		if (ecount >= 0)
			break;
		if (n->kids[kcount])
			n = n->kids[kcount];
		else
			break;
	}

	if (ecount >= 0) {
		/*
		 * We have found the element we're looking for. It's
		 * n->elems[ecount], at tree index idx. If our search
		 * relation is EQ, LE or GE we can now go home.
		 */
		if (relation != REL234_LT && relation != REL234_GT) {
			if (index)
				*index = idx;
			return n->elems[ecount];
		}

		/*
		 * Otherwise, we'll do an indexed lookup for the previous
		 * or next element. (It would be perfectly possible to
		 * implement these search types in a non-counted tree by
		 * going back up from where we are, but far more fiddly.)
		 */
		if (relation == REL234_LT)
			idx--;
		else
			idx++;
	} else {
		/*
		 * We've found our way to the bottom of the tree and we
		 * know where we would insert this node if we wanted to:
		 * we'd put it in in place of the (empty) subtree
		 * n->kids[kcount], and it would have index idx
		 * 
		 * But the actual element isn't there. So if our search
		 * relation is EQ, we're doomed.
		 */
		if (relation == REL234_EQ)
			return NULL;

		/*
		 * Otherwise, we must do an index lookup for index idx-1
		 * (if we're going left - LE or LT) or index idx (if we're
		 * going right - GE or GT).
		 */
		if (relation == REL234_LT || relation == REL234_LE) {
			idx--;
		}
	}

	/*
	 * We know the index of the element we want; just call index234
	 * to do the rest. This will return NULL if the index is out of
	 * bounds, which is exactly what we want.
	 */
	ret = index234(t, idx);
	if (ret && index)
		*index = idx;
	return ret;
}
// Materializing logical tile composed of two base tiles.
// The materialized tile's output columns are reordered.
// Also, one of the columns is dropped.
TEST_F(MaterializationTests, TwoBaseTilesWithReorderTest) {
  const int tuple_count = 9;
  std::shared_ptr<storage::TileGroup> tile_group(
      ExecutorTestsUtil::CreateTileGroup(tuple_count));

  ExecutorTestsUtil::PopulateTiles(tile_group, tuple_count);

  // Create logical tile from two base tiles.
  const std::vector<std::shared_ptr<storage::Tile> > source_base_tiles = {
      tile_group->GetTileReference(0), tile_group->GetTileReference(1)};

  // Add a reference because we are going to wrap around it and we don't own it
  std::unique_ptr<executor::LogicalTile> source_logical_tile(
      executor::LogicalTileFactory::WrapTiles(source_base_tiles));

  // Create materialization node for this test.
  // Construct output schema. We drop column 3 and reorder the others to 3,1,0.
  std::vector<catalog::Column> output_columns;
  // Note that Column 3 in the tile group is column 1 in the second tile.
  output_columns.push_back(source_base_tiles[1]->GetSchema()->GetColumn(1));
  output_columns.push_back(source_base_tiles[0]->GetSchema()->GetColumn(1));
  output_columns.push_back(source_base_tiles[0]->GetSchema()->GetColumn(0));
  std::shared_ptr<const catalog::Schema> output_schema(
      new catalog::Schema(output_columns));

  // Construct mapping using the ordering mentioned above.
  std::unordered_map<oid_t, oid_t> old_to_new_cols;
  old_to_new_cols[3] = 0;
  old_to_new_cols[1] = 1;
  old_to_new_cols[0] = 2;
  bool physify_flag = true;  // is going to create a physical tile
  planner::MaterializationPlan node(old_to_new_cols, output_schema,
                                    physify_flag);

  // Pass through materialization executor.
  executor::MaterializationExecutor executor(&node, nullptr);
  std::unique_ptr<executor::LogicalTile> result_logical_tile(
      ExecutorTestsUtil::ExecuteTile(&executor, source_logical_tile.release()));

  // Verify that logical tile is only made up of a single base tile.
  int num_cols = result_logical_tile->GetColumnCount();
  EXPECT_EQ(3, num_cols);
  storage::Tile *result_base_tile = result_logical_tile->GetBaseTile(0);
  EXPECT_THAT(result_base_tile, NotNull());
  EXPECT_EQ(result_base_tile, result_logical_tile->GetBaseTile(1));
  EXPECT_EQ(result_base_tile, result_logical_tile->GetBaseTile(2));

  // Check that the base tile has the correct values.
  for (int i = 0; i < tuple_count; i++) {
    type::Value val0(result_base_tile->GetValue(i, 0));
    type::Value val1(result_base_tile->GetValue(i, 1));
    type::Value val2(result_base_tile->GetValue(i, 2));
    // Output column 2.
    type::CmpBool cmp(val2.CompareEquals(
      type::ValueFactory::GetIntegerValue(ExecutorTestsUtil::PopulatedValue(i, 0))));
    EXPECT_TRUE(cmp == type::CMP_TRUE);

    // Output column 1.
    cmp = (val1.CompareEquals(type::ValueFactory::GetIntegerValue(
        ExecutorTestsUtil::PopulatedValue(i, 1))));
    EXPECT_TRUE(cmp == type::CMP_TRUE);

    // Output column 0.
    cmp = (val0.CompareEquals(type::ValueFactory::GetVarcharValue(
        std::to_string(ExecutorTestsUtil::PopulatedValue(i, 3)))));
    EXPECT_TRUE(cmp == type::CMP_TRUE);

    // Double check that logical tile is functioning.
    type::Value logic_val0 = (result_logical_tile->GetValue(i, 0));
    type::Value logic_val1 = (result_logical_tile->GetValue(i, 1));
    type::Value logic_val2 = (result_logical_tile->GetValue(i, 2));
    cmp = (logic_val0.CompareEquals(val0));
    EXPECT_TRUE(cmp == type::CMP_TRUE);
    cmp = (logic_val1.CompareEquals(val1));
    EXPECT_TRUE(cmp == type::CMP_TRUE);
    cmp = (logic_val2.CompareEquals(val2));
    EXPECT_TRUE(cmp == type::CMP_TRUE);
  }
}
Exemplo n.º 28
0
// Used by compiler only; may use only caller saved, non-argument registers
// NOTE:  %%%% if any change is made to this stub make sure that the function
//             pd_code_size_limit is changed to ensure the correct size for VtableStub
VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
  const int sparc_code_length = VtableStub::pd_code_size_limit(true);
  VtableStub* s = new(sparc_code_length) VtableStub(true, vtable_index);
  ResourceMark rm;
  CodeBuffer cb(s->entry_point(), sparc_code_length);
  MacroAssembler* masm = new MacroAssembler(&cb);

#ifndef PRODUCT
  if (CountCompiledCalls) {
    __ inc_counter(SharedRuntime::nof_megamorphic_calls_addr(), G5, G3_scratch);
  }
#endif /* PRODUCT */

  assert(VtableStub::receiver_location() == O0->as_VMReg(), "receiver expected in O0");

  // get receiver klass
  address npe_addr = __ pc();
  __ load_klass(O0, G3_scratch);

  // set methodOop (in case of interpreted method), and destination address
  int entry_offset = instanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size();
#ifndef PRODUCT
  if (DebugVtables) {
    Label L;
    // check offset vs vtable length
    __ ld(G3_scratch, instanceKlass::vtable_length_offset()*wordSize, G5);
    __ cmp(G5, vtable_index*vtableEntry::size());
    __ br(Assembler::greaterUnsigned, false, Assembler::pt, L);
    __ delayed()->nop();
    __ set(vtable_index, O2);
    __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), O0, O2);
    __ bind(L);
  }
#endif
  int v_off = entry_offset*wordSize + vtableEntry::method_offset_in_bytes();
  if( __ is_simm13(v_off) ) {
    __ ld_ptr(G3, v_off, G5_method);
  } else {
    __ set(v_off,G5);
    __ ld_ptr(G3, G5, G5_method);
  }

#ifndef PRODUCT
  if (DebugVtables) {
    Label L;
    __ br_notnull(G5_method, false, Assembler::pt, L);
    __ delayed()->nop();
    __ stop("Vtable entry is ZERO");
    __ bind(L);
  }
#endif

  address ame_addr = __ pc();  // if the vtable entry is null, the method is abstract
                               // NOTE: for vtable dispatches, the vtable entry will never be null.

  __ ld_ptr(G5_method, in_bytes(methodOopDesc::from_compiled_offset()), G3_scratch);

  // jump to target (either compiled code or c2iadapter)
  __ JMP(G3_scratch, 0);
  // load methodOop (in case we call c2iadapter)
  __ delayed()->nop();

  masm->flush();

  if (PrintMiscellaneous && (WizardMode || Verbose)) {
    tty->print_cr("vtable #%d at "PTR_FORMAT"[%d] left over: %d",
                  vtable_index, s->entry_point(),
                  (int)(s->code_end() - s->entry_point()),
                  (int)(s->code_end() - __ pc()));
  }
  guarantee(__ pc() <= s->code_end(), "overflowed buffer");
  // shut the door on sizing bugs
  int slop = 2*BytesPerInstWord;  // 32-bit offset is this much larger than a 13-bit one
  assert(vtable_index > 10 || __ pc() + slop <= s->code_end(), "room for sethi;add");

  s->set_exception_points(npe_addr, ame_addr);
  return s;
}
Exemplo n.º 29
0
Arquivo: clist.c Projeto: RIOT-OS/RIOT
clist_node_t *_clist_sort(clist_node_t *list, clist_cmp_func_t cmp)
{
    clist_node_t *p, *q, *e;
    int insize, psize, qsize, i;

    /*
     * Silly special case: if `list' was passed in as NULL, return
     * NULL immediately.
     */
    if (!list) {
        return NULL;
    }

    insize = 1;

    while (1) {
        clist_node_t *tail = NULL;
        clist_node_t *oldhead = list;
        p = list;
        list = NULL;

        int nmerges = 0;  /* count number of merges we do in this pass */

        while (p) {
            nmerges++;  /* there exists a merge to be done */
            /* step `insize' places along from p */
            q = p;
            psize = 0;
            for (i = 0; i < insize; i++) {
                psize++;
                q = (q->next == oldhead) ? NULL : q->next;
                /* cppcheck-suppress nullPointer
                 * (reason: possible bug in cppcheck 1.6x) */
                if (!q) {
                    break;
                }
            }

            /* if q hasn't fallen off end, we have two lists to merge */
            qsize = insize;

            /* now we have two lists; merge them */
            while (psize > 0 || (qsize > 0 && q)) {

                /* decide whether next element of merge comes from p or q */
                if (psize == 0) {
                    /* p is empty; e must come from q. */
                    e = q; q = q->next; qsize--;
                    if (q == oldhead) {
                        q = NULL;
                    }
                }
                else if (qsize == 0 || !q) {
                    /* q is empty; e must come from p. */
                    e = p; p = p->next; psize--;
                    if (p == oldhead) {
                        p = NULL;
                    }
                }
                else if (cmp(p, q) <= 0) {
                    /* First element of p is lower (or same);
                     * e must come from p. */
                    e = p; p = p->next; psize--;
                    if (p == oldhead) {
                        p = NULL;
                    }
                }
                else {
                    /* First element of q is lower; e must come from q. */
                    e = q; q = q->next; qsize--;
                    if (q == oldhead) {
                        q = NULL;
                    }
                }

                /* add the next element to the merged list */
                if (tail) {
                    tail->next = e;
                }
                else {
                    list = e;
                }
                tail = e;
            }

            /* now p has stepped `insize' places along, and q has too */
            p = q;
        }

        /* cppcheck-suppress nullPointer
         * (reason: tail cannot be NULL at this point, because list != NULL) */
        tail->next = list;

        /* If we have done only one merge, we're finished. */
        if (nmerges <= 1) { /* allow for nmerges==0, the empty list case */
            return tail;
        }

        /* Otherwise repeat, merging lists twice the size */
        insize *= 2;
    }
}
Exemplo n.º 30
0
// Helper to remove argument slots from the stack.
// arg_slots must be a multiple of stack_move_unit() and >= 0
void MethodHandles::remove_arg_slots(MacroAssembler* _masm,
                                     RegisterOrConstant arg_slots,
                                     Register argslot_reg,
                                     Register temp_reg, Register temp2_reg, Register temp3_reg) {
  assert(temp3_reg != noreg, "temp3 required");
  assert_different_registers(argslot_reg, temp_reg, temp2_reg, temp3_reg,
                             (!arg_slots.is_register() ? Gargs : arg_slots.as_register()));

  RegisterOrConstant offset = __ regcon_sll_ptr(arg_slots, LogBytesPerWord, temp3_reg);

#ifdef ASSERT
  // Verify that [argslot..argslot+size) lies within (Gargs, FP).
  __ add(argslot_reg, offset, temp2_reg);
  verify_argslot(_masm, temp2_reg, temp_reg, "deleted argument(s) must fall within current frame");
  if (arg_slots.is_register()) {
    Label L_ok, L_bad;
    __ cmp(arg_slots.as_register(), (int32_t) NULL_WORD);
    __ br(Assembler::less, false, Assembler::pn, L_bad);
    __ delayed()->nop();
    __ btst(-stack_move_unit() - 1, arg_slots.as_register());
    __ br(Assembler::zero, false, Assembler::pt, L_ok);
    __ delayed()->nop();
    __ bind(L_bad);
    __ stop("assert arg_slots >= 0 and clear low bits");
    __ bind(L_ok);
  } else {
    assert(arg_slots.as_constant() >= 0, "");
    assert(arg_slots.as_constant() % -stack_move_unit() == 0, "");
  }
#endif // ASSERT

  // Pull up everything shallower than argslot.
  // Then remove the excess space on the stack.
  // The stacked return address gets pulled up with everything else.
  // That is, copy [sp, argslot) upward by size words.  In pseudo-code:
  //   for (temp = argslot-1; temp >= sp; --temp)
  //     temp[size] = temp[0]
  //   argslot += size;
  //   sp += size;
  __ sub(argslot_reg, wordSize, temp_reg);  // source pointer for copy
  {
    Label loop;
    __ bind(loop);
    // pull one word up each time through the loop
    __ ld_ptr(Address(temp_reg, 0), temp2_reg);
    __ st_ptr(temp2_reg, Address(temp_reg, offset));
    __ sub(temp_reg, wordSize, temp_reg);
    __ cmp(temp_reg, Gargs);
    __ brx(Assembler::greaterEqual, false, Assembler::pt, loop);
    __ delayed()->nop();  // FILLME
  }

  // Now move the argslot up, to point to the just-copied block.
  __ add(Gargs, offset, Gargs);
  // And adjust the argslot address to point at the deletion point.
  __ add(argslot_reg, offset, argslot_reg);

  // Keep the stack pointer 2*wordSize aligned.
  const int TwoWordAlignmentMask = right_n_bits(LogBytesPerWord + 1);
  RegisterOrConstant masked_offset = __ regcon_andn_ptr(offset, TwoWordAlignmentMask, temp_reg);
  __ add(SP, masked_offset, SP);
}