libg722_1 0.1.0
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 * $Id: timing.h,v 1.1.1.1 2009/11/19 12:10:48 steveu Exp $
26 */
27
28#if !defined(_TIMING_H_)
29#define _TIMING_H_
30
31#if defined(__cplusplus)
32extern "C"
33{
34#endif
35
36#if defined(__MSVC__)
37__declspec(naked) unsigned __int64 __cdecl rdtscll(void)
38{
39 __asm
40 {
41 rdtsc
42 ret ; return value at EDX:EAX
43 }
44}
45/*- End of function --------------------------------------------------------*/
46#elif defined(__GNUC__)
47#if defined(__i386__)
48static __inline__ uint64_t rdtscll(void)
49{
50 uint64_t now;
51
52 __asm__ __volatile__(" rdtsc\n" : "=A" (now));
53 return now;
54}
55/*- End of function --------------------------------------------------------*/
56#elif defined(__x86_64__)
57static __inline__ uint64_t rdtscll(void)
58{
59 unsigned int a;
60 unsigned int d;
61
62 /* For x86_64 we need to merge the result in 2 32 bit registers
63 into one clean 64 bit result. */
64 __asm__ __volatile__(" rdtsc\n" : "=a" (a), "=d" (d));
65 return ((uint64_t) a) | (((uint64_t) d) << 32);
66}
67/*- End of function --------------------------------------------------------*/
68#else
69static __inline__ uint64_t rdtscll(void)
70{
71 /* This architecture doesn't have a suitable timer */
72 return 0llu;
73}
74/*- End of function --------------------------------------------------------*/
75#endif
76#endif
77
78#if defined(__cplusplus)
79}
80#endif
81
82#endif
83/*- End of file ------------------------------------------------------------*/