timing.h

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 
00026 #if !defined(_SPANDSP_TIMING_H_)
00027 #define _SPANDSP_TIMING_H_
00028 
00029 #if defined(__cplusplus)
00030 extern "C"
00031 {
00032 #endif
00033 
00034 #if defined(__MSVC__)
00035 __declspec(naked) unsigned __int64 __cdecl rdtscll(void)
00036 {
00037    __asm
00038    {
00039       rdtsc
00040       ret       ; return value at EDX:EAX
00041    }
00042 }
00043 /*- End of function --------------------------------------------------------*/
00044 #elif defined(__GNUC__)
00045 #if defined(__i386__)
00046 static __inline__ uint64_t rdtscll(void)
00047 {
00048     uint64_t now;
00049 
00050     __asm__ __volatile__(" rdtsc\n" : "=A" (now));
00051     return now;
00052 }
00053 /*- End of function --------------------------------------------------------*/
00054 #elif defined(__x86_64__)
00055 static __inline__ uint64_t rdtscll(void)
00056 {
00057     uint32_t a;
00058     uint32_t d;
00059 
00060     /* For x86_64 we need to merge the result in 2 32 bit registers
00061        into one clean 64 bit result. */
00062     __asm__ __volatile__(" rdtsc\n" : "=a" (a), "=d" (d));
00063     return ((uint64_t) a) | (((uint64_t) d) << 32);
00064 }
00065 /*- End of function --------------------------------------------------------*/
00066 #else
00067 static __inline__ uint64_t rdtscll(void)
00068 {
00069     /* This architecture doesn't have a suitable timer */
00070     return 0llu;
00071 }
00072 /*- End of function --------------------------------------------------------*/
00073 #endif
00074 #endif
00075 
00076 #if defined(__cplusplus)
00077 }
00078 #endif
00079 
00080 #endif
00081 /*- End of file ------------------------------------------------------------*/

Generated on 25 Jan 2012 for spandsp by  doxygen 1.6.1