/*
- * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
- *
* This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
*/
/**
* @file
* @brief OS abstraction from time measurement
* @author Sebastian Hack, Michael Beck, Matthias Braun
- * @version $Id$
*/
#ifndef FIRM_STAT_TIMING_H
#define FIRM_STAT_TIMING_H
#if defined(__GNUC__)
typedef unsigned long long timing_ticks_t;
-static inline timing_ticks_t __timing_ticks(void) { timing_ticks_t result; __asm__ __volatile__ ("rdtsc" : "=A" (result)); return result; }
+static inline timing_ticks_t __timing_ticks(void)
+{
+ unsigned h;
+ unsigned l;
+ __asm__ volatile("rdtsc" : "=a" (l), "=d" (h));
+ return (timing_ticks_t)h << 32 | l;
+}
#elif defined(_MSC_VER)
#include <intrin.h>
* /usr/include/sys/time.h
*/
#define timing_ticks_cmp(a, b, CMP) \
- (((a).tv_sec == (b).tv_sec) ? \
+ (((a).tv_sec == (b).tv_sec) ? \
((a).tv_usec CMP (b).tv_usec) : \
((a).tv_sec CMP (b).tv_sec))
#define timing_ticks_add(r, a) \
- do { \
+ do { \
(r).tv_sec = (r).tv_sec + (a).tv_sec; \
(r).tv_usec = (r).tv_usec + (a).tv_usec; \
- if ((r).tv_usec >= 1000000) { \
+ if ((r).tv_usec >= 1000000) { \
++(r).tv_sec; \
(r).tv_usec -= 1000000; \
- } \
+ } \
} while (0)
#define timing_ticks_sub(r, a) \
- do { \
- (r).tv_sec = (r).tv_sec - (a).tv_sec; \
+ do { \
+ (r).tv_sec = (r).tv_sec - (a).tv_sec; \
(r).tv_usec = (r).tv_usec - (a).tv_usec; \
- if ((r).tv_usec < 0) { \
- --(r).tv_sec; \
- (r).tv_usec += 1000000; \
- } \
+ if ((r).tv_usec < 0) { \
+ --(r).tv_sec; \
+ (r).tv_usec += 1000000; \
+ } \
} while (0)
#define timing_ticks_ulong(t) ((unsigned long) ((t).tv_usec + 1000000 * (t).tv_sec))