Пример #1
0
uint64_t getHKeyFromIntCoord( const int32_t m, const int32_t dim, const uint64_t * point, int * err ) {
	uint64_t result = 0;
	uint64_t TwoPowerOfM = 1 << m;

	uint64_t tmpPoint[dim];
	uint64_t tmp[dim];

	if( dim > HILB_MAX_DIM ) {
		*err = HKEY_ERR_DIM;
		return 0;
	}

	//check data sanity
	for(int i=0; i<dim; i++) {
		assert(point[i] >= 0);
	}

	memcpy(tmpPoint, point, dim * sizeof(uint64_t));
	memset(tmp, 0, dim);

	//clamp larger values to highest possible space on hilbert curve...
	for(int i=0; i<dim; i++) {
		if(tmpPoint[i] > TwoPowerOfM) {
			tmpPoint[i] = TwoPowerOfM - 1;
		}
	}

	//start constructing hilbert key
	for(uint64_t i=0; i<m; i++) {
		//step one: gather upper bits of coordinates
		for(int j=0; j<dim; j++) {
			tmp[j] = IBITS(tmpPoint[j], m-1-i, 1);
#ifdef VERBOSE
		printf("X\n");
		printf("m:%i - %i: %llu, %llu, %llu\n", m, j, i, tmpPoint[j], tmp[j]);
#endif			
		}

		uint64_t upperBitsOfPoint = 0;
		for(int j=0; j<dim; j++) {
			upperBitsOfPoint += tmp[j] << j;
		}

#ifdef VERBOSE	
		printf("X2\n");
		printf("%lli\n", upperBitsOfPoint);
#endif

		//reverse look up value in hilbert template to obtain key number (i.e. H-order)
		uint64_t hOrder = revC[dim-1][upperBitsOfPoint];

#ifdef VERBOSE
		printf("H-Order: %llu\n", hOrder);
#endif		

		//append H-order to result
		result = result << dim;
		result += hOrder;

#ifdef VERBOSE
		printf("R\n");
		printf("%lli\n", result);
#endif

		//perform exchange operation - first figure out which dimensions to exchange (and if...)
		//first isolate the two bits that decode the exchange - do nothing if they are not set
		// x & (-x) (i.e. 01011000 -> 00001000)
		uint32_t * currH = H[dim-1];
		int64_t exchange_gene = currH[hOrder * 2 + 0];
		int64_t reverse_gene = currH[hOrder * 2 + 1];
		uint64_t exDim1 = exchange_gene & (-1 * exchange_gene);
		uint64_t exDim2 = (uint64_t)exchange_gene ^ exDim1;					//this gets the other bit

		//we can have multiple reverses in one go. count them and execute them
		int32_t numReverses = pop64(reverse_gene);
		int64_t tmpReverse_gene = reverse_gene;

		for(int j=0; j<numReverses; j++) {
			int64_t revDim = tmpReverse_gene & ( -1 * tmpReverse_gene );
			tmpReverse_gene = tmpReverse_gene ^ revDim;

#ifdef VERBOSE
			printf("revDim%i: %i %i %i\n", j, tmpReverse_gene, -1 *  tmpReverse_gene, revDim);
#endif

			//reverse the dimensions - first isolating the dimension index by counting 0 bits
			int32_t dimIdx = ntz64(revDim);

			assert(dimIdx < dim);

#ifdef VERBOSE
			printf("Reverse%i %i: %x/%x\n", j, reverse_gene, revDim, dimIdx);
			printf("Reverse%i %i \n", j, tmpPoint[dimIdx]);
#endif

			tmpPoint[dimIdx] = tmpPoint[dimIdx] ^ 0xFFFFFFFFFFFFFFFF;			//reverse operation (i.e. 1011 -> 0100)
		}

		if(exDim1 != 0 && exDim2 != 0) {
			//exchange the dimensions - first isolating the dimension index by counting 0 bits
			int32_t dimIdx1 = ntz64(exDim1);
			int32_t dimIdx2 = ntz64(exDim2);

			assert(dimIdx1 < dim);
			assert(dimIdx2 < dim);

#ifdef VERBOSE
			printf("Exchange: %i, %x/%x <-> %x/%x\n", exchange_gene, exDim1, dimIdx1, exDim2, dimIdx2);
#endif

			uint64_t tmp;

			tmp = tmpPoint[dimIdx1];
			tmpPoint[dimIdx1] = tmpPoint[dimIdx2];
			tmpPoint[dimIdx2] = tmp;
		}

#ifdef VERBOSE	
		printf("C\n");
		printf("The key after iteration %u: ", i);
		for(int j=0; j < dim; j++) {
			printf("dim%i = %llu ", j, tmpPoint[j]);
		}

		printf("result = %llu\n", result);
#endif
	}

#ifdef VERBOSE
	printf("End result = %llu\n", result);
#endif

	*err = HKEY_ERR_OK;
	return result;
}
Пример #2
0
arm_instr_t arm_decode_instr(reg instr)
{
    arm_instr_t t = ARM_INSTR_ILLEGAL;

    if (IBITS(24, 4) == 0xF)                   return (ARM_INSTR_SWI);
    if (IBITS(25, 3) == BPAT3(1,0,1))          return (ARM_INSTR_B);
    if (IBITS(26, 2) == BPAT2(0,0)) {
        if (!IBIT(25) && !IBIT(4))             return (ARM_INSTR_AND + IBITS(21, 4));
        if (!IBIT(25) &&  IBIT(4) && !IBIT(7)) return (ARM_INSTR_AND + IBITS(21, 4));
        if ( IBIT(25))                         return (ARM_INSTR_AND + IBITS(21, 4));
    }
    if (IBITS(22,6) == 0 && IBITS(4,4) == 9)   return ARM_INSTR_MUL;
    if (IBITS(23,5) == 1 && IBITS(4,4) == 9)   return ARM_INSTR_MULL;

    if (IBITS(25,3) == 2) {
        /* Load/Store 12bit imm */
        if (IBIT(20))      return (ARM_INSTR_LDR);
        else               return (ARM_INSTR_STR);
    }
    
    if (IBITS(25,3) == 3 && !IBIT(4)) {
        if (IBIT(20))      return (ARM_INSTR_LDR);
        else               return (ARM_INSTR_STR);
    }

    if (!IBITS(25,3) && IBIT(7) && IBIT(4)) {
        if (IBIT(20)) {
            if (IBIT(22)) {
                if ( IBIT(6) &&  IBIT(5)) return (ARM_INSTR_LDSH);
                if ( IBIT(6) && !IBIT(5)) return (ARM_INSTR_LDSB);
                if (!IBIT(6) &&  IBIT(5)) return (ARM_INSTR_LDUH);
            }
            if (!IBIT(22) && !IBITS(8,4)) {
                if ( IBIT(6) &&  IBIT(5)) return (ARM_INSTR_LDSH);
                if ( IBIT(6) && !IBIT(5)) return (ARM_INSTR_LDSB);
                if (!IBIT(6) &&  IBIT(5)) return (ARM_INSTR_LDUH);
            }
        } else {
            if (IBIT(22)) {
                if (!IBIT(6) &&  IBIT(5)) return (ARM_INSTR_STH);
            }
            if (!IBIT(22) && !IBITS(8,4)) {
                if (!IBIT(6) &&  IBIT(5)) return (ARM_INSTR_STH);
            }
        }
    }

    if (IBITS(25, 3) == BPAT3(1,0,0)) {
        if (IBIT(20)) return (ARM_INSTR_LDM);
        else          return (ARM_INSTR_STM);
    }

    return t;
}
Пример #3
0
void getIntCoordFromHKey( uint64_t * outCoord, const int32_t m, const int32_t dim, const uint64_t key, int * err ) {
	uint64_t tmpKey = key;
	uint64_t flip = 0;

	memset(outCoord, 0, dim * sizeof(uint64_t));

	//checks
	assert(key >= 0);
	assert(key < (pow(2, dim*m)));

	uint64_t lowerNBits = IBITS(tmpKey, 0, dim);
	uint64_t partOnCurve = C[dim-1][lowerNBits];

#ifdef VERBOSE2
		printf("%lli %lli %lli\n", tmpKey, lowerNBits, partOnCurve);
		printf("R\n");
#endif

	for(int i=0; i<dim; i++) {
		outCoord[i] += IBITS(partOnCurve, i, 1);

#ifdef VERBOSE2
		printf("%i %lli\n", i, outCoord[i]);
#endif
	}

	for(int i=1; i<m; i++) {
		lowerNBits = IBITS(tmpKey, dim * i, dim);
		partOnCurve = C[dim-1][lowerNBits];

#ifdef VERBOSE2
		printf("%lli %lli %lli\n", tmpKey, lowerNBits, partOnCurve);
#endif

		//this is needed to perform the bit-flip (adding 111 at the end)
		flip = flip << 1;
		flip = flip + 1;

		//perform exchange operation - first figure out which dimensions to exchange (and if...)
		//first isolate the two bits that decode the exchange - do nothing if they are not set
		// x & (-x) (i.e. 01011000 -> 00001000)
		uint32_t * currH = H[dim-1];
		int64_t exchange_gene = currH[lowerNBits * 2 + 0];
		int64_t reverse_gene = currH[lowerNBits * 2 + 1];
		uint64_t exDim1 = exchange_gene & (-1 * exchange_gene);
		uint64_t exDim2 = (uint64_t)exchange_gene ^ exDim1;					//this gets the other bit

		//we can have multiple reverses in one go. count them and execute them
		int32_t numReverses = pop64(reverse_gene);
		int64_t tmpReverse_gene = reverse_gene;

		if(exDim1 != 0 && exDim2 != 0) {
			//exchange the dimensions - first isolating the dimension index by counting 0 bits
			int32_t dimIdx1 = ntz64(exDim1);
			int32_t dimIdx2 = ntz64(exDim2);

			assert(dimIdx1 < dim);
			assert(dimIdx2 < dim);

			uint64_t tmp;

#ifdef VERBOSE2
			printf("Exchange: %i, %x/%x <-> %x/%x\n", exchange_gene, exDim1, dimIdx1, exDim2, dimIdx2);
#endif

			tmp = outCoord[dimIdx1];
			outCoord[dimIdx1] = outCoord[dimIdx2];
			outCoord[dimIdx2] = tmp;
		}

		for(int j=0; j<numReverses; j++) {
			int64_t revDim = tmpReverse_gene & ( -1 * tmpReverse_gene );
			tmpReverse_gene = tmpReverse_gene ^ revDim;

			//reverse the dimensions - first isolating the dimension index by counting 0 bits
			int32_t dimIdx = ntz64(revDim);

			assert(dimIdx < dim);

#ifdef VERBOSE2
			printf("Reverse%i %i: %x/%x\n", j, reverse_gene, revDim, dimIdx);
			printf("Reverse%i %i \n", j, outCoord[dimIdx]);
#endif

			outCoord[dimIdx] = outCoord[dimIdx] ^ flip;			//reverse operation (i.e. 1011 -> 0100)
		}

#ifdef VERBOSE2
		printf("semi-new outCoord:\n");
		for(int j=0; j<dim; j++) {
			printf("%i %lli\n", j, outCoord[j]);
		}
		printf("R\n");
#endif

		for(int j=0; j<dim; j++) {
			outCoord[j] += IBITS(partOnCurve, j, 1) << i;
#ifdef VERBOSE2
			printf("%i %lli\n", j, outCoord[j]);
#endif			
		}
	}

	*err = HKEY_ERR_OK;
	return;
}
Пример #4
0
arm_cond_t arm_decode_cond(reg instr)
{
    return IBITS(28,4);
}