00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * timing.h - Provide access to the Pentium/Athlon TSC timer register 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2001 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 2.1, 00014 * as published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 * 00025 * $Id: timing.h,v 1.13 2008/04/17 14:27:01 steveu Exp $ 00026 */ 00027 00028 #if !defined(_SPANDSP_TIMING_H_) 00029 #define _SPANDSP_TIMING_H_ 00030 00031 #if defined(__cplusplus) 00032 extern "C" 00033 { 00034 #endif 00035 00036 #if defined(__MSVC__) 00037 __declspec(naked) unsigned __int64 __cdecl rdtscll(void) 00038 { 00039 __asm 00040 { 00041 rdtsc 00042 ret ; return value at EDX:EAX 00043 } 00044 } 00045 /*- End of function --------------------------------------------------------*/ 00046 #elif defined(__GNUC__) 00047 #if defined(__i386__) 00048 static __inline__ uint64_t rdtscll(void) 00049 { 00050 uint64_t now; 00051 00052 __asm__ __volatile__(" rdtsc\n" : "=A" (now)); 00053 return now; 00054 } 00055 /*- End of function --------------------------------------------------------*/ 00056 #elif defined(__x86_64__) 00057 static __inline__ uint64_t rdtscll(void) 00058 { 00059 unsigned int a; 00060 unsigned int d; 00061 00062 /* For x86_64 we need to merge the result in 2 32 bit registers 00063 into one clean 64 bit result. */ 00064 __asm__ __volatile__(" rdtsc\n" : "=a" (a), "=d" (d)); 00065 return ((uint64_t) a) | (((uint64_t) d) << 32); 00066 } 00067 /*- End of function --------------------------------------------------------*/ 00068 #else 00069 static __inline__ uint64_t rdtscll(void) 00070 { 00071 /* This architecture doesn't have a suitable timer */ 00072 return 0llu; 00073 } 00074 /*- End of function --------------------------------------------------------*/ 00075 #endif 00076 #endif 00077 00078 #if defined(__cplusplus) 00079 } 00080 #endif 00081 00082 #endif 00083 /*- End of file ------------------------------------------------------------*/