void exp()

in src/CodeSetSize/CodeSetSize.cpp [127:165]


void exp(F trans, const int memSize, bool nop=false)
{
	auto buf = (char*)VirtualAlloc(nullptr, memSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
	if (!buf)
	{
		cerr << "Argh 0\n";
		return;
	}

	ErrorHistogram e;
	if (nop)
	{
		fillBuffer<uint8_t>(buf, memSize, 0x90);
	}
	else
	{
		constexpr uint16_t andEcxEcx = 0xc921;
		fillBuffer<uint16_t>(buf, memSize, andEcxEcx);
	}

	// write "jmp rax" to the end of the buffer
	buf[memSize - 2] = 255;
	buf[memSize - 1] = 224;

	_mm_mfence();
	double cycles = 0;
	for (int i = 0; i < nRetries; i++)
	{
		auto t0 = __rdtsc();
		auto status = trans(buf);
		auto t1 = __rdtsc();
		e[status]++;
		if (status == _XBEGIN_STARTED) cycles += t1 - t0;
		Sleep(0);
	}
	cout << "Executed " << memSize
		<< " nops. Average cycles on success: " << cycles / e[_XBEGIN_STARTED]
		<< " Errors:\n" << e << "\n";
}