Exemplo n.º 1
1
int main()
{
	Code code;
	void (*f)() = code.getCode<void (*)()>();
	dump(code.getCode(), code.getSize());
	f();
}
Exemplo n.º 2
0
// Compares guess to secret code and returns the number of correct digits
// in the incorrect locations.
int Code::checkIncorrect(Code& guess) {
    const int secretCodeLength = getLength();
    int count = 0; // correct digits in the incorrect location
	vector<bool> secretUsed = getUsed();
	vector<bool> guessUsed = guess.getUsed();
    
    /// check vector lengths
	if (guess.getLength() != secretCodeLength) {
		throw InvalidVectSize("Code::checkCorrect - vectors are not the same length!");
	}

	// compare all unused guess values to current unused secret code value
	for (int i = 0; i < secretCodeLength; i++) {
		for (int j = 0; j < guess.getLength(); j++) {
			if ((!secretUsed[i] && !guessUsed[j]) &&
				(getCode()[i] == guess.getCode()[j] )) {
				// we have a match, mark these indices as used and 
				// increase the count before continuing the compare
				secretUsed[i] = true;
				guessUsed[j] = true;
				count++;
				break;
			}
		}
	}
    return count;
}
Exemplo n.º 3
0
int main()
{
	const int count = 1000;
	Xbyak::util::Clock clk;
	Code c;
	void (*f)() = (void (*)())c.getCode();
	for (int i = 0; i < count; i++) {
		clk.begin();
		f();
		clk.end();
	}
	printf("%.3fclk\n", clk.getClock() / double(N) / clk.getCount());
}
Exemplo n.º 4
0
// Compares guess to secret code and returns the number of correct digits
// in the correct locations.
int Code::checkCorrect(Code& guess) {
    const int secretCodeLength = getLength();
    int count = 0;
	vector<bool> correct(secretCodeLength, false);

	/// check vector lengths
    if (guess.getLength() != secretCodeLength) {
        throw InvalidVectSize("Code::checkCorrect - vectors are not the same length!");
    }

    for (int i = 0; i < guess.getLength(); i++) {
        if (getCode()[i] == guess.getCode()[i]) {
			// mark both the secret and guess code index values if used
			correct[i] = true;
			count++; 
		}
    }
	setUsed(correct);
	guess.setUsed(correct);
    return count;
}
Exemplo n.º 5
0
void bench(int mode)
{
	const int N = 100000;
	Code code;
	code.makeBench(N, mode);
	int (*p)(uint64_t*, const uint64_t*, const uint64_t*) = (int (*)(uint64_t*, const uint64_t*, const uint64_t*))code.getCode();

	uint64_t a[4] = { uint64_t(-1), uint64_t(-2), uint64_t(-3), 544443221 };
	uint64_t b[4] = { uint64_t(-123), uint64_t(-3), uint64_t(-4), 222222222 };
	uint64_t c[5] = { 0, 0, 0, 0, 0 };

	const int M = 100;
	Xbyak::util::Clock clk;
	for (int i = 0; i < M; i++) {
		clk.begin();
		p(c, a, b);
		clk.end();
	}
	printf("%.2fclk\n", clk.getClock() / double(M) / double(N) / innerN);
}