projects
/
lttv.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update
[lttv.git]
/
ltt
/
branches
/
poly
/
ltt
/
time.h
diff --git
a/ltt/branches/poly/ltt/time.h
b/ltt/branches/poly/ltt/time.h
index 6ab53fcac3039310e11dae5c4593c91dee4be5f9..14c15d1d237c1d7d184033636750a510a63e8e16 100644
(file)
--- a/
ltt/branches/poly/ltt/time.h
+++ b/
ltt/branches/poly/ltt/time.h
@@
-1,5
+1,6
@@
/* This file is part of the Linux Trace Toolkit trace reading library
* Copyright (C) 2003-2004 Michel Dagenais
/* This file is part of the Linux Trace Toolkit trace reading library
* Copyright (C) 2003-2004 Michel Dagenais
+ * 2005 Mathieu Desnoyers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@
-21,6
+22,7
@@
#include <glib.h>
#include <ltt/compiler.h>
#include <glib.h>
#include <ltt/compiler.h>
+#include <math.h>
typedef struct _LttTime {
unsigned long tv_sec;
typedef struct _LttTime {
unsigned long tv_sec;
@@
-29,10
+31,17
@@
typedef struct _LttTime {
#define NANOSECONDS_PER_SECOND 1000000000
#define NANOSECONDS_PER_SECOND 1000000000
+
+/* We give the DIV and MUL constants so we can always multiply, for a
+ * division as well as a multiplication of NANOSECONDS_PER_SECOND */
/* 2^30/1.07374182400631629848 = 1000000000.0 */
/* 2^30/1.07374182400631629848 = 1000000000.0 */
-#define DOUBLE_SHIFT_CONST 1.07374182400631629848
+#define DOUBLE_SHIFT_CONST
_DIV
1.07374182400631629848
#define DOUBLE_SHIFT 30
#define DOUBLE_SHIFT 30
+/* 2^30*0.93132257461547851562 = 1000000000.0000000000 */
+#define DOUBLE_SHIFT_CONST_MUL 0.93132257461547851562
+
+
/* 1953125 * 2^9 = NANOSECONDS_PER_SECOND */
#define LTT_TIME_UINT_SHIFT_CONST 1953125
#define LTT_TIME_UINT_SHIFT 9
/* 1953125 * 2^9 = NANOSECONDS_PER_SECOND */
#define LTT_TIME_UINT_SHIFT_CONST 1953125
#define LTT_TIME_UINT_SHIFT 9
@@
-109,7
+118,7
@@
static inline double ltt_time_to_double(LttTime t1)
g_warning("Precision loss in conversion LttTime to double");
#endif //EXTRA_CHECK
return ((double)((guint64)t1.tv_sec<<DOUBLE_SHIFT)
g_warning("Precision loss in conversion LttTime to double");
#endif //EXTRA_CHECK
return ((double)((guint64)t1.tv_sec<<DOUBLE_SHIFT)
-
/ (double)DOUBLE_SHIFT_CONST
)
+
* (double)DOUBLE_SHIFT_CONST_MUL
)
+ (double)t1.tv_nsec;
}
+ (double)t1.tv_nsec;
}
@@
-131,7
+140,7
@@
static inline LttTime ltt_time_from_double(double t1)
#endif //EXTRA_CHECK
LttTime res;
//res.tv_sec = t1/(double)NANOSECONDS_PER_SECOND;
#endif //EXTRA_CHECK
LttTime res;
//res.tv_sec = t1/(double)NANOSECONDS_PER_SECOND;
- res.tv_sec = (guint64)(t1 * DOUBLE_SHIFT_CONST) >> DOUBLE_SHIFT;
+ res.tv_sec = (guint64)(t1 * DOUBLE_SHIFT_CONST
_DIV
) >> DOUBLE_SHIFT;
res.tv_nsec = (t1 - (((guint64)res.tv_sec<<LTT_TIME_UINT_SHIFT))
* LTT_TIME_UINT_SHIFT_CONST);
return res;
res.tv_nsec = (t1 - (((guint64)res.tv_sec<<LTT_TIME_UINT_SHIFT))
* LTT_TIME_UINT_SHIFT_CONST);
return res;
@@
-205,7
+214,7
@@
static inline LttTime ltt_time_div(LttTime t1, double d)
static inline guint64 ltt_time_to_uint64(LttTime t1)
{
static inline guint64 ltt_time_to_uint64(LttTime t1)
{
- return (
guint64)((t1.tv_sec*LTT_TIME_UINT_SHIFT_CONST) >>
LTT_TIME_UINT_SHIFT)
+ return (
((guint64)t1.tv_sec*LTT_TIME_UINT_SHIFT_CONST) <<
LTT_TIME_UINT_SHIFT)
+ (guint64)t1.tv_nsec;
}
+ (guint64)t1.tv_nsec;
}
This page took
0.023495 seconds
and
4
git commands to generate.