//(C) João Carlos Ferreira Gonçalves / CK / C3R14L.K1L4
#include <Windows.h>
#include "HighResolutionTime.h"
#include <jni.h>

static LARGE_INTEGER qpc;
static LARGE_INTEGER pqf;
static LARGE_INTEGER rdtsc_v;

JNIEXPORT jlong JNICALL Java_HighResolutionTime_QueryPerformanceCounter (JNIEnv *algo, jclass otro)
{
	if(QueryPerformanceCounter(&qpc))
		return qpc.QuadPart;
	else return 0;
}

JNIEXPORT jlong JNICALL Java_HighResolutionTime_QueryPerformanceFrequency (JNIEnv *algo, jclass otro)
{
	if(QueryPerformanceFrequency(&pqf))
		return pqf.QuadPart;
	else return 0;
}

JNIEXPORT jlong JNICALL Java_HighResolutionTime_getRDTSC (JNIEnv *algo, jclass otro)
{
	__asm 
	{
		_emit 0xf  
		_emit 0x31   
		mov rdtsc_v.HighPart, edx
		mov rdtsc_v.LowPart, eax
	}
	return rdtsc_v.QuadPart;
}
