#if defined(__aarch64__)
#include "KunpengTrans.h"
#endif
#ifndef getticks_h
#define getticks_h

// ~3 x 10^9 ticks/sec

#ifdef _MSC_VER
#include <Windows.h>
typedef unsigned __int64 TICKS;

#define	GetClockTicks	__rdtsc

#elif __GNUC__

typedef uint64_t TICKS;
__inline__ uint64_t GetClockTicks()
	{
	uint32_t lo, hi;
	/* We cannot use "=A", since this would use %rax on x86_64 */
	#if defined(__x86_64__)
              __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
 
#elif defined(__aarch64__)
       // Description: Replace with the converted code block suggested. Note:
       // Suggestion: 
       //    {
       unsigned int _kp_tmp_CPUFreq = KUNPENG_CPU_FREQUENCY_MHZ; 
       unsigned long long _kp_tmp_TSCCount; 
       unsigned long long _kp_tmp_TSCFreq; 
       __asm__ __volatile__ ("mrs %0, cntfrq_el0" : "=r" (_kp_tmp_TSCFreq)); 
       __asm__ __volatile__ ("mrs %0, cntvct_el0" : "=r" (_kp_tmp_TSCCount)); 
       lo = (unsigned int)(_kp_tmp_TSCCount * _kp_tmp_CPUFreq / _kp_tmp_TSCFreq); 
       hi = (unsigned int)((_kp_tmp_TSCCount * _kp_tmp_CPUFreq / _kp_tmp_TSCFreq) >> 32); 
       // }
#endif
        return (uint64_t)hi << 32 | lo;
	}

#else
#error	"getticks_h, unknown compiler"
#endif

#endif // getticks_h
