spandsp 0.0.6
timing.h
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * timing.h - Provide access to the Pentium/Athlon TSC timer register
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2001 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#if !defined(_SPANDSP_TIMING_H_)
27#define _SPANDSP_TIMING_H_
28
29#if defined(__cplusplus)
30extern "C"
31{
32#endif
33
34#if defined(__MSVC__)
35__declspec(naked) unsigned __int64 __cdecl rdtscll(void)
36{
37 __asm
38 {
39 rdtsc
40 ret ; return value at EDX:EAX
41 }
42}
43/*- End of function --------------------------------------------------------*/
44#elif defined(__GNUC__)
45#if defined(__i386__)
46static __inline__ uint64_t rdtscll(void)
47{
48 uint64_t now;
49
50 __asm__ __volatile__(" rdtsc\n" : "=A" (now));
51 return now;
52}
53/*- End of function --------------------------------------------------------*/
54#elif defined(__x86_64__)
55static __inline__ uint64_t rdtscll(void)
56{
57 uint32_t a;
58 uint32_t d;
59
60 /* For x86_64 we need to merge the result in 2 32 bit registers
61 into one clean 64 bit result. */
62 __asm__ __volatile__(" rdtsc\n" : "=a" (a), "=d" (d));
63 return ((uint64_t) a) | (((uint64_t) d) << 32);
64}
65/*- End of function --------------------------------------------------------*/
66#else
67static __inline__ uint64_t rdtscll(void)
68{
69 /* This architecture doesn't have a suitable timer */
70 return 0llu;
71}
72/*- End of function --------------------------------------------------------*/
73#endif
74#endif
75
76#if defined(__cplusplus)
77}
78#endif
79
80#endif
81/*- End of file ------------------------------------------------------------*/